The WixDataAggregatePipelineExpressions methods provide a set of operators and functions for performing calculations, transformations, and field manipulations within aggregation pipelines. These expressions are essential building blocks used by pipeline stages to process your data.
Each expression method either resolves to a value or returns another expression that you can use as input for other methods. This composability allows you to build complex calculations and transformations that execute efficiently within the database layer. Available expressions include numeric operations such as add and multiply, text operations such as concat and toUpper, and field selection operations such as field().
Use expressions in the Project stage when calling reshape(), or when calculating group values in the Group stage.
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.
To use WixDataAggregatePipelineExpressions methods:
Set up the @wix/data package and import it in your code:
Deconstruct the pipelineBuilder, expressions, and stages submodules to access their methods:
You can now call WixDataAggregatePipelineExpressions methods using dot notation. For example, the following code calculates the tax on the price of item, adds the tax to the price, and creates a new field with the final item price:
Note: The data type of the value the expression resolves to must adhere to the operation you want to perform. For example, when calling abs(), you must specify an expression that resolves to a number. When calling concat(), you can only specify expressions that resolve to strings.
Learn more about data types in Wix Data.
When you've configured the stages you want to apply to your data, include them in the desired order as elements in the stages array. Specify them to the withStages() method, and run the pipeline:
Learn more about pipelineBuilder() and the PipelineBuilder methods.