Search.../

skip( )

Sets the number of items or groups to skip before returning aggregation results.

Description

The skip() function defines the number of results to skip in the aggregation results before returning new aggregation results.

For example, if you perform an aggregation on a collection and 10 groups match your aggregation, but you set skip to 3, the results returned will skip the first 3 groups that match and return the 4th through 10th items.

By default, skip is set to 0.

Note: Aggregations can only be used on collections you have created. They cannot be used on Wix App Collections.

Authorization

Request

This endpoint does not take any parameters

Response Object

A WixDataAggregate object representing the refined aggregation.

Returns an empty object.

Status/Error Codes

Was this helpful?

Add a skip to an aggregation

Copy Code
1let newAggregate = aggregate.skip(10);
Create an aggregate, add a skip, and run it

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.aggregate("PopulationData")
6 .group("state", "year")
7 .max("population")
8 .skip(3)
9 .run()
10 .then((results) => {
11 if (results.items.length > 0) {
12 let items = results.items; // see below
13 let numItems = results.length; // 3
14 let hasNext = results.hasNext();
15 } else {
16 // handle case where no matching items found
17 }
18 })
19 .catch((error) => {
20 let errorMsg = error.message;
21 let code = error.code;
22 });
23
24/* Given the sample data above, items is:
25 * [
26 * {
27 * "_id": {"state": "FL", "year": 2010},
28 * "populationMax":401000,
29 * "state": "FL",
30 * "year": 2010
31 * }, {
32 * "_id": {"state": "CA", "year": 2010},
33 * "populationMax":3796000,
34 * "state": "CA",
35 * "year": 2010
36 * }, {
37 * "_id": {"state": "NY", "year": 2010},
38 * "populationMax":8192000,
39 * "state": "NY",
40 * "year": 2010
41 * }
42 * ]
43 */
Create an aggregation with filtering and grouping and run it

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5const filter = wixData.filter().eq("year", 2010);
6const having = wixData.filter().gt("maxPopulation", 1000000);
7
8wixData.aggregate("PopulationData")
9 .filter(filter)
10 .group("state")
11 .max("population", "maxPopulation")
12 .having(having)
13 .descending("maxPopulation")
14 .skip(5)
15 .limit(3)
16 .run()
17 .then((results) => {
18 if (results.items.length > 0) {
19 let items = results.items;
20 let numItems = results.length;
21 let hasNext = results.hasNext();
22 } else {
23 // handle case where no matching items found
24 }
25 })
26 .catch((error) => {
27 let errorMsg = error.message;
28 let code = error.code;
29 });