Search...
next( )
Retrieves the next page of aggregate results.
Description
The next()
function retrieves the next page of aggregate results.
The page size is defined by the limit()
function.
If items are added or removed between calls to next()
the values returned
by WixDataAggregateResult
may change.
Syntax
function next(): Promise<WixDataAggregateResult>
next Parameters
This function does not take any parameters.
Returns
Fulfilled - An aggregate object with the next page of aggregate results. Rejected - The errors that caused the rejection.
Return Type:
Promise<WixDataAggregateResult>
Was this helpful?
Get the next page of an aggregate result
Copy Code
1oldResults.next()2 .then((newResults) => {3 let items = newResults.items;4 let numItems = newResults.length;5 let hasNext = newResults.hasNext();6 })7 .catch((error) => {8 let errorMsg = error.message;9 let code = error.code;10 });
Iterate through all pages of aggregate results
Copy Code
1let results = await wixData.aggregate("Cities")2 .group("city")3 .limit(3)4 .run();56console.log(results.items);78while(results.hasNext()) {9 console.log("---▼ Next Page ▼---");10 results = await results.next();11 console.log(results.items);12}1314/* Logs:15 * [{"_id":"San Diego"},{"_id":"Orlando"},{"_id":"San Francisco"}]16 * ---▼ Next Page ▼---17 * [{"_id":"Buffalo"},{"_id":"Miami"},{"_id":"Los Angeles"}]18 * ---▼ Next Page ▼---19 * [{"_id":"Miami"}]20 */