Search...
limit( )
Limits the number of items the query returns.
Description
The limit()
function defines the number of results a query returns in each
page. Only one page of results is retrieved at a time. The next()
and prev()
functions are used to
navigate the pages of a query result.
By default, limit
is set to 50
.
The maximum value that limit()
can accept is 1000
.
Note that for some Wix app collections, the maximum value limit()
can accept is
less than 1000
. For example, the maximum limit for the Wix Stores/Product
collection is 100.
Authorization
Request
This endpoint does not take any parameters
Response Object
A WixDataQuery
object representing the refined query.
Returns an empty object.
Status/Error Codes
Was this helpful?
Add a limit to a query
Copy Code
1let newQuery = query.limit(10);
Create a query, add a limit, and run it
Copy Code
1import wixData from 'wix-data';23// ...45wixData.query("myCollection")6 .limit(10)7 .find()8 .then((results) => {9 if(results.items.length > 0) {10 let items = results.items;11 let firstItem = items[0];12 let totalCount = results.totalCount;13 let pageSize = results.pageSize;14 let currentPage = results.currentPage;15 let totalPages = results.totalPages;16 let hasNext = results.hasNext();17 let hasPrev = results.hasPrev();18 let length = results.length;19 let query = results.query;20 } else {21 // handle case where no matching items found22 }23 })24 .catch((error) => {25 let errorMsg = error.message;26 let code = error.code;27 });
Create a query, add a limit, and run it
Copy Code
1import wixData from 'wix-data';23// ...45wixData.query("myCollection")6 .eq("status", "active")7 .gt("age", 25)8 .ascending("last_name", "first_name")9 .limit(10)10 .find()11 .then((results) => {12 if(results.items.length > 0) {13 let items = results.items;14 let firstItem = items[0];15 let totalCount = results.totalCount;16 let pageSize = results.pageSize;17 let currentPage = results.currentPage;18 let totalPages = results.totalPages;19 let hasNext = results.hasNext();20 let hasPrev = results.hasPrev();21 let length = results.length;22 let query = results.query;23 } else {24 // handle case where no matching items found25 }26 })27 .catch((error) => {28 let errorMsg = error.message;29 let code = error.code;30 });
Iterate through all pages of query results
This example demonstrates how to get all query results, bypassing the maximum limit of 1000.
Copy Code
1async function retrieveAllItems() {2 let results = await wixData.query("myCollection")3 .limit(1000)4 .find();5 let allItems = results.items;6 while (results.hasNext()) {7 results = await results.next();8 allItems = allItems.concat(results.items);9 }10 return allItems;11}