Search.../

run( )

Runs the aggregation and returns the results.

Description

The run() function returns a Promise that resolves to the results found by the aggregation and some information about the results.

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

Syntax

function run([options: RunOptions]): Promise<WixDataAggregateResult>

run Parameters

NAME
TYPE
DESCRIPTION
options
Optional
RunOptions

Options to use when running an aggregation.

Returns

Fulfilled - A Promise that resolves to the results of the aggregation. Rejected - Error that caused the aggregation to fail.

Return Type:

Was this helpful?

Perform an aggregation

Copy Code
1aggregate.run()
2 .then((results) => {
3 if (results.items.length > 0) {
4 let items = results.items;
5 let numItems = results.length;
6 let hasNext = results.hasNext();
7 } else {
8 // handle case where no matching items found
9 }
10 })
11 .catch((error) => {
12 let errorMsg = error.message;
13 let code = error.code;
14 });
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 });