Returning more than 1000 items with wixData.query()

Hello, I had this problem for a while so I figured I’d share the solution. Query recursively increasing the index by 1000 and logging the results each time.

async function getAllItems ( db , index ) {
return wixData . query ( db )
. limit ( 1000 )
. skip ( index )
. find ()
. then ( async ( res ) => {
allItems . push ( res.items )
if ( res.items.length === 1000 ) {
index += 1000 ;
return await getAllItems ( db , index )
}
else {
return allItems ;
}
})
}


Then use it like this:


let allItems = [];
let index = 0;
async function test() {
    let db = 'db_name';
    return getAllItems(db, index)
}

This isn’t super fast, so maybe there is a better implementation. Good luck out there.

1 Like