The WixDataAggregatePipelineStages
methods enable you to process collection items through a series of stages. Each stage performs a different type of operation on the items passed to it and outputs the results to the next stage in the pipeline. By combining stages, you can filter, group, sort, or reshape your data.
Note: You can only run the aggregation pipeline on collections created in the CMS or with the Data Collections API. They cannot be used on Wix app collections or external collections.
Build an aggregation pipeline by adding one or more of the following stages in the desired order:
The filter stage lets you configure which items to move to the next stage. Call filter()
and chain FilterStage
methods to configure the filter criteria.
Learn more about filters in API Query Language.
The group stage lets you organize items into groups and perform calculations on each group. Call group()
and chain GroupStage
methods to specify which items to group, how to group them, and which calculations to perform on each group.
The limit stage lets you set the maximum number of items to move to the next stage. Call limit()
to set the limit the results.
The object to array stage lets you convert an object field into an array. Call objectToArray()
to specify the object to convert and the key of the destination array.
The project stage lets you create new result items by including, excluding, or transforming existing fields. Call project()
and chain ProjectStage
methods to configure the projection.
The skip stage lets you set the number of items to skip before moving to the next stage. Call skip()
to specify how many results to skip.
The sort stage lets you sort the results in the specified order before moving to the next stage. Call sort()
and chain SortStage
methods to specify the sort order and priority.
Learn more about sorting in API Query Language.
The unwind array stage lets you deconstruct an array into separate result items. Call unwind()
to specify the array to unwind.
To access WixDataAggregatePipelineStages
methods:
Set up the @wix/data
package and import it in your code:
Deconstruct the stages
submodule to use its methods:
You can now call WixDataAggregatePipelineStages
methods using dot notation. For example, the following code groups items whose color
field has the same value into a result item with a color
property. It then counts the number of items that have the same color: