Hi,
I'm trying to query my dataset to get the unique list of values from a column called 'makeclean'. The below formula worked but my dataset is now bigger than 1,000 - it's up to about 10,000 so the below no longer works.
const setMakeDropdown = () => {
wixData.query("Scraper")
.limit(1000)
.find()
.then(res => {
// Filter duplicates and reorder
let makes = res.items.map(({ makeclean }) => makeclean);
makes = [...new Set(makes)].sort();
// Create makes options list
let options = [{ 'value': "", 'label': "Any Make" }];
options.push(...makes.map(makeclean => {
return { "value": makeclean, "label": makeclean };
}));
$w('#makeDropdown').options = options;
})
};
Instead using the below code to search through all 10,000 results. How can I link the below code into the above code to search all 10,000 results and then display them in a dropdown list (sorted and with duplicates removed [this is what the code above does])
async function fetchData() {
let result = await wixData.query("Scraper")
.limit(1000)
.find(); // Result is WixDataQueryResult and has next() method
let allItems = result.items;
while (result.hasNext()) { // Repeat while there is a next page
result = await result.next(); // We fetch next page the easy way, without using skip and limit
allItems = allItems.concat(result.items); // We add results of the next page to allItems
}
return allItems; // In the end we return the list of items from all pages
}
Thank you so much,
Giles
Hi @Giles Gunning, the query actually find all the matched items, but only return up to 1000 item at a time, this limitation is to make the query process a lot faster, if you checked the returned items count, they will not be more than 1000, but if you want to know the total number of the all matching items, use the totalCount instead.
Here's an example, you searched a 10K entries database, for a value that has a 315 matching item, here's what each line will return to you.
wixData.query("Scraper").limit(100).find().then((result) => { let returnedItems = result.items.length; let matchingItems = result.totalCount; console.log(returnedItems); // Expect 100 console.log(matchingItems); // Expect 315 })
Notice the difference between them, each one of them has its own use.
Hope that helped!
Ahamd