The aggregation pipeline lets you perform complex data transformations and calculations on collections. This guide explains how to build and run an aggregation pipeline. A pipeline consists of 1 or more stages that process your data sequentially, with each stage's output becoming the input for the next stage. The pipeline allows you to:
Note: You can only build an aggregation pipeline for collections created in the CMS or with the Data Collections API. You can't use them on Wix app collections or external collections.
aggregatePipeline()
: Runs an aggregation pipeline on a specified collection and returns the results.pipelineBuilder()
: Builds an aggregation pipeline with stages and pagination configuration.To run an aggregation pipeline, first build it by calling pipelineBuilder()
. After you build it, specify the pipeline to the aggregatePipeline()
method to retrieve the aggregated results:
Import the items
module and deconstruct the required submodules:
Add 1 or more stages to build the pipeline:
Some stages use expressions to resolve the values required for the specified operation:
Specify the stages array to the withStages()
method. You can also add paging configuration with the withPaging()
method. Finally, call build()
to build the pipeline:
Your pipeline is now ready.
Specify the configured pipeline to the aggregatePipeline()
method to run the pipeline: