How to filter and get more than 1000 results from a dataset?

Hello folks,

I’m trying to filter by some dataset field and get more than 1000 results, i’m currently doing this:

async function fetchProductData(categories) {

 let result = await wixData.query('Produtos')
    .hasSome("categorias", categoriesID)
    .limit(1000)
    .find()

 let allItems = result.items;
 
 while (result.hasNext()) {
        result = await result.next();
        allItems = allItems.concat(result.items);
    }
 return allItems;
}

But the result.hasNext() is never true and I never get more than 1000 results. Hown can I do that?

https://www.wix.com/corvid/forum/community-discussion/dataset-query-for-9000-items-for-dropdown

Thanks for the answer,

I could get more than 1000 itens without using

.hasSome("categorias", categoriesID)

But every time I try to use it in the query i get only 1000 itens, do you know how can i work around this?

@sorrisimdiv
Hello again,

normaly the given code in the link which i gave you, should solve your problem.

let allItems = [];
let hasNext = true;
let count = 0
while(hasNext){
    let result = await wixData.query('wix19')                      .limit(1000).skip(count).find();
    count += result.items.length;
    hasNext = result.hasNext();
    allItems.concat(result.items)
}

I am not sure, but this CODE here should collect first all RESULTS in an ARRAY (“allItems”) and then put them together.

Did you tried a console-log-command to take a look at the END-RESULT of “allItems” ???

Do a console-log —>

console.log(allItems.lenght) 

or something like this, to check the lenght of the result-data. Then you will see how much items are in the data at the end of the function-process.