Getting more than 3k items in a dropdown

Hello I found below code in some old post and I’m trying to figure out how to make it work.
I have a data collection with more than 3k item and I need to let the user pick one of the item.
I divided the 3k items into few categories and I created second dropdown menu in order to filter them but that’s not good,the user need to be able to type the name of one of the item and choose it in a dropdown menu without prior filter.

This code looks good enough but I can’t find a place to put i.

I have an input text and drop down, should I put it under on click event? Or when page is loaded function?

“The below code will search a database column (“fieldKey”) for items that match the value you type into your input box. Change the following variables : (DatabaseID, fieldKey, input1, dropdown1) async function getUniqueListFromDatabase() { const List1 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(”#input1").value) .limit(1000) .ascending(“fieldKey”) .find() const List2 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(“#input1”).value) .limit(1000) .skip(1000) .ascending(“fieldKey”) .find() const List3 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(“#input1”).value) .limit(1000) .skip(2000) .ascending(“fieldKey”) .find() const List4 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(“#input1”).value) .limit(1000) .skip(3000) .ascending(“fieldKey”) .find() const mergedLists = List1.items.concat(List2.items).concat(List3.items).concat(List4.items) const uniqueItems = getUniqueTitles(mergedLists); $w(“#dropdown1”).options = buildOptions(uniqueItems); function getUniqueTitles(items) { const titlesOnly = items.map(item => item.fieldKey); // don’t forget to change this field key return […new Set(titlesOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return { label: curr, value: curr }; }); } }"

Thank you!

Please format the code first. It’s hard to read it like that.

Sorry, i copy past if from my cell phone and i haven’t seen that.
here is the code:

async function getUniqueListFromDatabase() {

const List1 = await wixData.query(“Stocks_Sectors”)

        .contains("symbol", $w("#input11").value) 

        .limit(1000) 

        .ascending("symbol") 

        .find() 

const List2 = await wixData.query(“Stocks_Sectors”)

        .contains("symbol", $w("#input11").value) 

        .limit(1000) 

        .skip(1000) 

        .ascending("symbol") 

        .find() 

const List3 = await wixData.query(“Stocks_Sectors”)

        .contains("symbol", $w("#input11").value) 

        .limit(1000) 

        .skip(2000) 

        .ascending("symbol") 

        .find() 

const List4 = await wixData.query(“Stocks_Sectors”)

        .contains("symbol", $w("#input11").value) 

        .limit(1000) 

        .skip(3000) 

        .ascending("symbol") 

        .find() 

const mergedLists = List1.items.concat(List2.items).concat(List3.items).concat(List4.items)

const uniqueItems = getUniqueTitles(mergedLists);

    $w("#dropdown1").options = buildOptions(uniqueItems); 

function getUniqueTitles(items) {

const titlesOnly = items.map(item => item.symbol); // don’t forget to change this field key

return […new Set(titlesOnly)];

    } 

function buildOptions(uniqueList) {

return uniqueList.map(curr => {

return { label: curr, value: curr };

        }); 

    } 
}

@meirhasin you can put it wherever you want (but not before the import).
But you should call the getUniqueListFromDatabase(), from inside the $w.onReady() function.

Might I add that Corvid docs actually offer an elegant solution to bypass the skip/limit approach:

Iterate through all pages of query results

This example demonstrates how to get all query results, bypassing the maximum limit of 1000.
Copy Code

let allItems = [];

let results = await wixData.query("myCollection")
    .limit(1000)
    .find();

allItems.push(results.items);

while(results.hasNext()) {
    results = await results.next();
    allItems.push(results.items);
}

Source : WixDataQuery - Velo API Reference - Wix.com

Thank you, do you have some practice example? how to combine it with dropdown menu?.
Thanks!
I

The script is working and i’m able to fetch all the elements in my database and create array for each one of them.
But how can i look for specific field in the database and let the user to choose is from dropdown menu or search input field?.
Thank you.

I managed to get all values of specific field in the data collection, all i need now is to add them to the dropdown/search input field.
can you please help me?.
That’s what i have so far but the dropdown part at the end is not working:

let allItems = [];
let all_symbols = [];
let results = await wixData.query(“Stocks_Sectors”)
.isNotEmpty(“symbol”)
.limit(1000)
.find();
let _symbol = results.symbol;
//console.log(_symbol);
allItems.push(results.items);
while (results.hasNext()) {
results = await results.next();
//console.log(results.items)
allItems.push(results.items);
var merged = [].concat.apply([], allItems);
// console.log(merged)
for ( var key in merged) {
if (merged.hasOwnProperty(key)) {
all_symbols.push(merged[key][“symbol”])

}
$w(“#dropdown9”).options = all_symbols;
console.log(all_symbols)
}}}

Thank you