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 (like add
, multiply
), text operations (like concat
, toUpper
), and field access operations.
Use expressions in the Project stage when calling reshape()
, or when calculating some 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 expressions
submodule to use its 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.