> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# AggregatePipelineDataItems

# Package: cms

# Namespace: DataItemService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/aggregate-pipeline-data-items.md

## Permission Scopes:
Read Data Items: SCOPE.DC-DATA.READ

## Introduction

Runs an aggregation pipeline on a data collection and returns the results.

Aggregations enable you to perform advanced data calculations, transformations, and groupings. While [Aggregate Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/aggregate-data-items.md) allows you to perform basic aggregations, Aggregate Pipeline Data Items allows you to perform advanced aggregations sequentially in stages, with each stage transforming the results of the previous stage.

---

## REST API

### Schema

```
 Method: aggregatePipelineDataItems
 Description: Runs an aggregation pipeline on a data collection and returns the results.  Aggregations enable you to perform advanced data calculations, transformations, and groupings. While [Aggregate Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/aggregate-data-items.md) allows you to perform basic aggregations, Aggregate Pipeline Data Items allows you to perform advanced aggregations sequentially in stages, with each stage transforming the results of the previous stage.
 URL: https://www.wixapis.com/wix-data/v2/items/aggregate-pipeline
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  dataCollectionId
 Method parameters: 
   param name: appOptions | type: appOptions | description: Additional parameters specific to the [Wix app collection](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections) you are querying.  Learn more about [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md).  
   param name: consistentRead | type: consistentRead | description: Whether to read from the primary database for the most current data.  This decreases performance but ensures data retrieved is up to date even immediately after an update.  Learn more about [Wix Data and eventual consistency](https://dev.wix.com/api/rest/wix-data/wix-data/eventual-consistency).  Default: `false`.  
   param name: dataCollectionId | type: dataCollectionId | description: GUID of the collection to run the aggregation pipeline on. | required: true | validation: maxLength 256
   param name: language | type: language | description: Language to run the aggregation in, in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format.  When provided, the aggregation runs on items in the specified language. When not provided, the aggregation runs on items in the default language.  > **Note:** The Wix user must enable translation for the specified language in [Wix Multilingual](https://www.wix.com/app-market/wix-multilingual).  Learn more about [using Wix Multilingual to translate CMS content](https://support.wix.com/en/article/wix-multilingual-translating-cms-collection-content).  | validation: format LANGUAGE_TAG
   param name: pipeline | type: AggregationPipeline    
    - ONE-OF: 
     - name: paging | type: Paging | description: Paging options to limit and skip the number of results.  Learn more about [sorting and paging](https://dev.wix.com/docs/rest/articles/get-started/sorting-and-paging.md).  
        - name: limit | type: integer | description: Number of items to load.  | validation: minimum 0, format int32
        - name: offset | type: integer | description: Number of items to skip in the current sort order.  | validation: minimum 0, format int32
     - name: cursorPaging | type: CursorPaging | description: Cursor token referring to a page of results.  Not used in the first request. Subsequent requests use the cursor token and not `filter` or `sort`.  
        - name: limit | type: integer | description: Number of items to load.  | validation: minimum 0, maximum 1000, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  You can get the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 150000
        - name: stages | type: array<Stage> | description: Sequence of aggregation operations to apply to the data.  Stages are processed in order, with each stage operating on the output of the previous stage.  | validation: maxItems 100
           - ONE-OF: 
              - name: group | type: Group | description: Groups aggregated items to new result items.  
                 - name: groupIds | type: array<GroupId> | description: Grouping criteria by which to organize items.  Each `groupId` specifies a field by which to group items, and serves as the result item's unique `_id` property.  Items with identical values for the specified `expression` are placed in the same group based on the specified `key`. If empty, all items are treated as a single group.  | validation: maxItems 1000
                    - name: key | type: string | description: Name of the field to group items by.  This becomes the field name in the result's `_id` property.  | validation: maxLength 1000
                    - name: expression | type: Expression | description: Expression to determine the grouping value. Items whose expression resolves to the same value are grouped together in the result item's `_id` property.  
                       - ONE-OF: 
                          - name: fieldPath | type: string | description: Path to the field containing the value to resolve.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`.  | validation: maxLength 1000
                          - name: text | type: string | description: Text value.  | validation: maxLength 1000
                          - name: numeric | type: number | description: Number value.  
                          - name: add | type: AddOperation | description: Adds the specified expressions together.  
                             - name: expressions | type: array<Expression> | description: Expressions to add together.  All expressions must resolve to numbers.  | validation: maxItems 1000
                          - name: sum | type: SumOperation | description: Calculates the total sum of multiple expressions.  
                             - name: expressions | type: array<Expression> | description: Expressions to calculate the total sum of.  All expressions must resolve to numbers.  | validation: maxItems 1000
                          - name: subtract | type: SubtractOperation | description: Subtracts 1 expression from another.  
                             - name: firstExpression | type: Expression | description: Expression to subtract `secondExpression` from.  Expression must resolve to a number.  
                             - name: secondExpression | type: Expression | description: Expression to subtract from `firstExpression`.  Expression must resolve to a number.  
                          - name: multiply | type: MultiplyOperation | description: Multiplies multiple expressions together.  
                             - name: expressions | type: array<Expression> | description: Expressions to multiply.  All expressions must resolve to numbers.  | validation: maxItems 1000
                          - name: divide | type: DivideOperation | description: Divides 1 expression by another.  
                             - name: firstExpression | type: Expression | description: Expression to divide by `secondExpression`.  Expression must resolve to a number.  
                             - name: secondExpression | type: Expression | description: Expression to divide `firstExpression` by.  Expression must resolve to a non-zero number.  
                          - name: abs | type: AbsOperation | description: Finds the absolute value of an expression.  
                             - name: expression | type: Expression | description: Expression to find the absolute value of.  Expression must resolve to a number.  
                          - name: mod | type: ModOperation | description: Finds the remainder when dividing 1 expression by another.  
                             - name: firstExpression | type: Expression | description: Expression to divide by `secondExpression` to find the remainder.  Expression must resolve to a number.  
                             - name: secondExpression | type: Expression | description: Expression to divide `firstExpression` by.  Expression must resolve to a non-zero number.  
                          - name: floor | type: FloorOperation | description: Rounds an expression down to the nearest whole number.  
                             - name: expression | type: Expression | description: Expression to round down to the nearest whole number.  Expression must resolve to a number.  
                          - name: ceil | type: CeilOperation | description: Rounds an expression up to the nearest whole number.  
                             - name: expression | type: Expression | description: Expression to round up to the nearest whole number.  Expression must resolve to a number.  
                          - name: concat | type: ConcatOperation | description: Joins multiple expressions together to create a string.  
                             - name: expressions | type: array<Expression> | description: Expressions to join together.  All expressions must resolve to strings.  | validation: maxItems 1000
                          - name: stringify | type: StringifyOperation | description: Converts an expression to a string.  
                             - name: expression | type: Expression | description: Expression to convert to a string.  
                          - name: toLower | type: ToLowerOperation | description: Converts an expression to lowercase.  
                             - name: expression | type: Expression | description: Expression to convert to lowercase.  Expression must resolve to a string.  
                          - name: toUpper | type: ToUpperOperation | description: Converts an expression to uppercase.  
                             - name: expression | type: Expression | description: Expression to convert to uppercase.  Expression must resolve to a string.  
                          - name: substring | type: SubstringOperation | description: Extracts a portion of a string expression.  
                             - name: expression | type: Expression | description: Expression to extract a substring from.  Expression must resolve to a string.  
                             - name: startExpression | type: Expression | description: Starting position of the substring to extract, specified in zero-based indexing.  Expression must resolve to a number.  
                             - name: lengthExpression | type: Expression | description: Number of characters to extract from the starting position.  Expression must resolve to a number.  
                          - name: length | type: LengthOperation | description: Finds the length of a string expression.  
                             - name: expression | type: Expression | description: Expression to count the total number of characters of.  Expression must resolve to a string.  
                          - name: boolean | type: boolean | description: Boolean value.  
                          - name: condition | type: ConditionOperation | description: Returns one of two expressions based on a condition.  
                             - name: ifExpression | type: Expression | description: Expression to evaluate as a condition.  
                             - name: whenTrue | type: Expression | description: Expression to return when `ifExpression` resolves to `true`.  
                             - name: whenFalse | type: Expression | description: Expression to return when `ifExpression` resolves to `false`.  
                          - name: gt | type: GreaterThanOperation | description: Checks whether the first expression is greater than the second expression.  
                             - name: firstExpression | type: Expression | description: Expression on the left side of the comparison.  
                             - name: secondExpression | type: Expression | description: Expression on the right side of the comparison.  
                          - name: size | type: SizeOperation | description: Returns the number of elements in an array expression.  
                             - name: expression | type: Expression | description: Expression containing the array whose size to return.  
                 - name: accumulators | type: array<Accumulator> | description: Accumulation operations to run on each group.  Accumulators aggregate data across all items in the group and return the result in a new field.  > **Note:** When using accumulators, the type of expression must be compatible with the operation type. For example, when using the `sum` accumulator, the specified expression must resolve to a number.  | validation: maxItems 1000
                    - ONE-OF: 
                       - name: avg | type: Avg | description: Calculates the average value across all items in the group based on the specified expression.  
                          - name: expression | type: Expression | description: Expression to calculate the group's average value.  Expression must resolve to a number.  
                       - name: min | type: Min | description: Finds the minimum value across all items in the group.  
                          - name: expression | type: Expression | description: Expression to find the group's minimum value.  Expression must resolve to a comparable value, such as a number or string.  
                       - name: max | type: Max | description: Finds the maximum value across all items in the group.  
                          - name: expression | type: Expression | description: Expression to find the group's maximum value.  Expression must resolve to a comparable value, such as a number or string.  
                       - name: sum | type: Sum | description: Calculates the sum of the specified expression across all items in the group.  
                          - name: expression | type: Expression | description: Expression to calculate the group's total sum.  Expression must resolve to a number.  
                       - name: first | type: First | description: Finds the first item in the group.  
                          - name: expression | type: Expression | description: Expression to find the first item in the group.  
                       - name: last | type: Last | description: Finds the last item in the group.  
                          - name: expression | type: Expression | description: Expression to find the last item in the group.  
                       - name: push | type: Push | description: Collects values from all items in the group into an array.  
                          - name: expression | type: Expression | description: Expression to collect items into an array.  
                    - name: resultFieldName | type: string | description: Field key in the output item to store the result in.  | validation: maxLength 1000
              - name: filter | type: object | description: Aggregation filter. Only items that match the filter are processed.  Learn more about [filters in API Query Language](https://dev.wix.com/docs/rest/articles/get-started/api-query-language.md#filters).  > **Note:** The values you provide for each filter field must adhere to that field's data type. For example, when filtering by a field whose type is Date and Time, use an object in the following format: `"someDateAndTimeFieldKey": { "$date": "YYYY-MM-DDTHH:mm:ss.sssZ"}`. Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/data-types-in-wix-data.md).  
              - name: sort | type: Sorting | description: Sorting preferences.  Learn more about [sorting and paging](https://dev.wix.com/docs/rest/articles/get-started/sorting-and-paging.md).  
                 - name: values | type: array<Sorting> | description: Fields to sort the results by.  | validation: maxItems 1000
                    - name: fieldName | type: string | description: Name of the field to sort by.  | validation: minLength 1, maxLength 1000
                    - name: order | type: SortOrder | description: Sort order.  
                             - enum: ASC, DESC
              - name: projection | type: Projection | description: Transforms items by including, excluding, or reshaping fields.  
                 - name: fields | type: array<Field> | description: Fields to include, exclude, or reshape.  | validation: maxItems 1000
                    - ONE-OF: 
                       - name: include | type: Include | description: When specified, includes only the specified field in the result. All other fields are excluded.  
                          - name: fieldName | type: string | description: Key of the field to include in the result.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                       - name: exclude | type: Exclude | description: When specified, excludes the specified field from the result. All other fields are included.  
                          - name: fieldName | type: string | description: Key of the field to exclude from the result.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                       - name: reshape | type: Reshape | description: Reshapes a new field based on the specified expression. The field used by the expression is not included in the result.  
                          - name: resultFieldName | type: string | description: Key of the field to create in the result item.  Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                          - name: expression | type: Expression | description: Expression to resolve. The result of the expression becomes the value of the new field.  
                       - name: projectNested | type: ProjectNested | description: Creates nested fields by including, excluding, or reshaping fields.  
                          - name: resultFieldName | type: string | description: Key of the parent field for the nested fields.  Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                          - name: fields | type: array<Field> | description: Nested fields to include, exclude, or reshape.  | validation: maxItems 1000
              - name: objectToArray | type: ObjectToArray | description: Transforms an object into an array where each object property becomes a new array element containing the property's key and value, as well as all other properties from the original object.  
                 - name: objectFieldName | type: string | description: Key of the object field to convert to an array.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                 - name: destinationFieldName | type: string | description: Key of the new array to create in the result item.  Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
              - name: unwindArray | type: UnwindArray | description: Creates a result item for each array element. Each result contains the full original item, with the array field replaced by an element whose key is the array name and whose value is the array element.  
                 - name: arrayFieldName | type: string | description: Key of the array field to unwind.  Use dot notation to specify a nested array. For example, `user.products` or `product.colors`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
              - name: skip | type: integer | description: Number of results to skip from the beginning of the result set.  
              - name: limit | type: integer | description: Maximum number of results to return.  
              - name: addFields | type: AddFields | description: Adds or replaces fields in each result item.  
                 - name: fields | type: array<AddField> | description: Fields to add or replace in the result items.  | validation: maxItems 1000
                    - name: fieldName | type: string | description: Key of the field to add or replace in the result item.  | validation: maxLength 1000
                    - name: expression | type: Expression | description: Expression to resolve. The result of the expression becomes the value of the field.  
              - name: lookup | type: Lookup | description: Joins items from another collection into an array field by matching a local field against a foreign field.  
                 - name: dataCollectionId | type: string | description: GUID of the collection to join with.  | validation: maxLength 256
                 - name: localField | type: string | description: Key of the local field whose value is used for matching items in the joined collection.  | validation: maxLength 1000
                 - name: foreignField | type: string | description: Key of the field in the joined collection to match against the local field value.  | validation: maxLength 1000
                 - name: asField | type: string | description: Key of the array field where matching joined items are stored.  | validation: maxLength 1000
              - name: unionWith | type: UnionWith | description: Appends results from another collection pipeline to the current results.  
                 - name: dataCollectionId | type: string | description: GUID of the collection whose results are appended to the current pipeline results.  | validation: maxLength 256
                 - name: pipeline | type: AggregationPipeline | description: Pipeline to run on the union collection before appending its results.  
                    - ONE-OF: 
                    - name: stages | type: array<Stage> | description: Sequence of aggregation operations to apply to the data.  Stages are processed in order, with each stage operating on the output of the previous stage.  | validation: maxItems 100
   param name: publishPluginOptions | type: PublishPluginOptions    
        - name: includeDraftItems | type: boolean | description: Whether to include draft items.  When `true`, both published and draft items are affected. Default: `false`.  
   param name: returnTotalCount | type: returnTotalCount | description: Whether to return the total result count when running a query with offset paging. When `true`, the `pagingMetadata` property in the response contains a `total` field.  Learn more about [offset paging](https://dev.wix.com/docs/rest/articles/get-started/sorting-and-paging.md#paging).  Default: `false`.  
 Return type: AggregatePipelineDataItemsResponse
  - name: results | type: array | description: Aggregation results.  | validation: maxItems 10000
  - name: pagingMetadata | type: PagingMetadataV2 | description: Paging information.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: offset | type: integer | description: Offset that was requested.  | validation: format int32
     - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used, `returnTotalCount` is `true` in the request, and `tooManyToCount` is false.  | validation: format int32
     - name: tooManyToCount | type: boolean | description: Whether the server failed to calculate the `total` field.  
     - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used.  
        - name: next | type: string | description: Cursor pointing to next page in the list of results.  | validation: maxLength 150000
        - name: prev | type: string | description: Cursor pointing to previous page in the list of results.  | validation: maxLength 150000


```

### Examples

### Find the 5 most densely populated cities with 500K+ residents
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v2/items/aggregate-pipeline' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
  "dataCollectionId": "cities",
  "pipeline": {
    "stages": [
      {"filter": {"population": {"$gt": 500000}}},
      {"projection": {
        "fields": [
          {"include": {"fieldName": "city"}},
          {"include": {"fieldName": "state"}},
          {"include": {"fieldName": "population"}},
          {"include": {"fieldName": "area"}},
          {"reshape": {
            "resultFieldName": "populationDensity",
            "expression": {"divide": {
              "firstExpression": {"fieldPath": "population"},
              "secondExpression": {"fieldPath": "area"}
            }}
          }},
          {"reshape": {
            "resultFieldName": "cityInfo",
            "expression": {"concat": {
              "expressions": [{"fieldPath": "city"}, {"text": ", "}, {"fieldPath": "state"}]
            }}
          }}
        ]
      }},
      {"sort": {"values": [{"fieldName": "populationDensity", "order": "DESC"}]}},
      {"limit": 5}
    ]
  }
}'
```

### Group cities by state and calculate average population per state
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v2/items/aggregate-pipeline' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
  "dataCollectionId": "cities",
  "pipeline": {
    "stages": [
      {"filter": {"year": 2022}},
      {"group": {
        "groupIds": [{"key": "state", "expression": {"fieldPath": "state"}}],
        "accumulators": [
          {"resultFieldName": "avgPopulation", "avg": {"expression": {"fieldPath": "population"}}},
          {"resultFieldName": "cityCount", "sum": {"expression": {"numeric": 1}}}
        ]
      }},
      {"sort": {"values": [{"fieldName": "avgPopulation", "order": "DESC"}]}}
    ]
  }
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.data.items.aggregatePipeline(dataCollectionId, pipeline, options)
 Description: Runs an aggregation pipeline on a data collection and returns the results.  Aggregations enable you to perform advanced data calculations, transformations, and groupings. While [Aggregate Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/aggregate-data-items.md) allows you to perform basic aggregations, Aggregate Pipeline Data Items allows you to perform advanced aggregations sequentially in stages, with each stage transforming the results of the previous stage.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  dataCollectionId, pipeline
 Method parameters: 
   param name: dataCollectionId | type: string | description: GUID of the collection to run the aggregation pipeline on. | required: true | validation: maxLength 256
   param name: pipeline | type: AggregationPipeline   | required: true 
    - ONE-OF: - required: true
     - name: paging | type: Paging | description: Paging options to limit and skip the number of results.  Learn more about [sorting and paging](https://dev.wix.com/docs/rest/articles/get-started/sorting-and-paging.md).  
        - name: limit | type: integer | description: Number of items to load.  | validation: minimum 0, format int32
        - name: offset | type: integer | description: Number of items to skip in the current sort order.  | validation: minimum 0, format int32
     - name: cursorPaging | type: CursorPaging | description: Cursor token referring to a page of results.  Not used in the first request. Subsequent requests use the cursor token and not `filter` or `sort`.  
        - name: limit | type: integer | description: Number of items to load.  | validation: minimum 0, maximum 1000, format int32
        - name: cursor | type: string | description: Pointer to the next or previous page in the list of results.  You can get the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request.  | validation: maxLength 150000
        - name: stages | type: array<Stage> | description: Sequence of aggregation operations to apply to the data.  Stages are processed in order, with each stage operating on the output of the previous stage.  | validation: maxItems 100
           - ONE-OF: 
              - name: group | type: Group | description: Groups aggregated items to new result items.  
                 - name: groupIds | type: array<GroupId> | description: Grouping criteria by which to organize items.  Each `groupId` specifies a field by which to group items, and serves as the result item's unique `_id` property.  Items with identical values for the specified `expression` are placed in the same group based on the specified `key`. If empty, all items are treated as a single group.  | validation: maxItems 1000
                    - name: key | type: string | description: Name of the field to group items by.  This becomes the field name in the result's `_id` property.  | validation: maxLength 1000
                    - name: expression | type: Expression | description: Expression to determine the grouping value. Items whose expression resolves to the same value are grouped together in the result item's `_id` property.  
                       - ONE-OF: 
                          - name: fieldPath | type: string | description: Path to the field containing the value to resolve.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`.  | validation: maxLength 1000
                          - name: text | type: string | description: Text value.  | validation: maxLength 1000
                          - name: numeric | type: number | description: Number value.  
                          - name: add | type: AddOperation | description: Adds the specified expressions together.  
                             - name: expressions | type: array<Expression> | description: Expressions to add together.  All expressions must resolve to numbers.  | validation: maxItems 1000
                          - name: sum | type: SumOperation | description: Calculates the total sum of multiple expressions.  
                             - name: expressions | type: array<Expression> | description: Expressions to calculate the total sum of.  All expressions must resolve to numbers.  | validation: maxItems 1000
                          - name: subtract | type: SubtractOperation | description: Subtracts 1 expression from another.  
                             - name: firstExpression | type: Expression | description: Expression to subtract `secondExpression` from.  Expression must resolve to a number.  
                             - name: secondExpression | type: Expression | description: Expression to subtract from `firstExpression`.  Expression must resolve to a number.  
                          - name: multiply | type: MultiplyOperation | description: Multiplies multiple expressions together.  
                             - name: expressions | type: array<Expression> | description: Expressions to multiply.  All expressions must resolve to numbers.  | validation: maxItems 1000
                          - name: divide | type: DivideOperation | description: Divides 1 expression by another.  
                             - name: firstExpression | type: Expression | description: Expression to divide by `secondExpression`.  Expression must resolve to a number.  
                             - name: secondExpression | type: Expression | description: Expression to divide `firstExpression` by.  Expression must resolve to a non-zero number.  
                          - name: abs | type: AbsOperation | description: Finds the absolute value of an expression.  
                             - name: expression | type: Expression | description: Expression to find the absolute value of.  Expression must resolve to a number.  
                          - name: mod | type: ModOperation | description: Finds the remainder when dividing 1 expression by another.  
                             - name: firstExpression | type: Expression | description: Expression to divide by `secondExpression` to find the remainder.  Expression must resolve to a number.  
                             - name: secondExpression | type: Expression | description: Expression to divide `firstExpression` by.  Expression must resolve to a non-zero number.  
                          - name: floor | type: FloorOperation | description: Rounds an expression down to the nearest whole number.  
                             - name: expression | type: Expression | description: Expression to round down to the nearest whole number.  Expression must resolve to a number.  
                          - name: ceil | type: CeilOperation | description: Rounds an expression up to the nearest whole number.  
                             - name: expression | type: Expression | description: Expression to round up to the nearest whole number.  Expression must resolve to a number.  
                          - name: concat | type: ConcatOperation | description: Joins multiple expressions together to create a string.  
                             - name: expressions | type: array<Expression> | description: Expressions to join together.  All expressions must resolve to strings.  | validation: maxItems 1000
                          - name: stringify | type: StringifyOperation | description: Converts an expression to a string.  
                             - name: expression | type: Expression | description: Expression to convert to a string.  
                          - name: toLower | type: ToLowerOperation | description: Converts an expression to lowercase.  
                             - name: expression | type: Expression | description: Expression to convert to lowercase.  Expression must resolve to a string.  
                          - name: toUpper | type: ToUpperOperation | description: Converts an expression to uppercase.  
                             - name: expression | type: Expression | description: Expression to convert to uppercase.  Expression must resolve to a string.  
                          - name: substring | type: SubstringOperation | description: Extracts a portion of a string expression.  
                             - name: expression | type: Expression | description: Expression to extract a substring from.  Expression must resolve to a string.  
                             - name: startExpression | type: Expression | description: Starting position of the substring to extract, specified in zero-based indexing.  Expression must resolve to a number.  
                             - name: lengthExpression | type: Expression | description: Number of characters to extract from the starting position.  Expression must resolve to a number.  
                          - name: length | type: LengthOperation | description: Finds the length of a string expression.  
                             - name: expression | type: Expression | description: Expression to count the total number of characters of.  Expression must resolve to a string.  
                          - name: boolean | type: boolean | description: Boolean value.  
                          - name: condition | type: ConditionOperation | description: Returns one of two expressions based on a condition.  
                             - name: ifExpression | type: Expression | description: Expression to evaluate as a condition.  
                             - name: whenTrue | type: Expression | description: Expression to return when `ifExpression` resolves to `true`.  
                             - name: whenFalse | type: Expression | description: Expression to return when `ifExpression` resolves to `false`.  
                          - name: gt | type: GreaterThanOperation | description: Checks whether the first expression is greater than the second expression.  
                             - name: firstExpression | type: Expression | description: Expression on the left side of the comparison.  
                             - name: secondExpression | type: Expression | description: Expression on the right side of the comparison.  
                          - name: size | type: SizeOperation | description: Returns the number of elements in an array expression.  
                             - name: expression | type: Expression | description: Expression containing the array whose size to return.  
                 - name: accumulators | type: array<Accumulator> | description: Accumulation operations to run on each group.  Accumulators aggregate data across all items in the group and return the result in a new field.  > **Note:** When using accumulators, the type of expression must be compatible with the operation type. For example, when using the `sum` accumulator, the specified expression must resolve to a number.  | validation: maxItems 1000
                    - ONE-OF: 
                       - name: avg | type: Avg | description: Calculates the average value across all items in the group based on the specified expression.  
                          - name: expression | type: Expression | description: Expression to calculate the group's average value.  Expression must resolve to a number.  
                       - name: min | type: Min | description: Finds the minimum value across all items in the group.  
                          - name: expression | type: Expression | description: Expression to find the group's minimum value.  Expression must resolve to a comparable value, such as a number or string.  
                       - name: max | type: Max | description: Finds the maximum value across all items in the group.  
                          - name: expression | type: Expression | description: Expression to find the group's maximum value.  Expression must resolve to a comparable value, such as a number or string.  
                       - name: sum | type: Sum | description: Calculates the sum of the specified expression across all items in the group.  
                          - name: expression | type: Expression | description: Expression to calculate the group's total sum.  Expression must resolve to a number.  
                       - name: first | type: First | description: Finds the first item in the group.  
                          - name: expression | type: Expression | description: Expression to find the first item in the group.  
                       - name: last | type: Last | description: Finds the last item in the group.  
                          - name: expression | type: Expression | description: Expression to find the last item in the group.  
                       - name: push | type: Push | description: Collects values from all items in the group into an array.  
                          - name: expression | type: Expression | description: Expression to collect items into an array.  
                    - name: resultFieldName | type: string | description: Field key in the output item to store the result in.  | validation: maxLength 1000
              - name: filter | type: object | description: Aggregation filter. Only items that match the filter are processed.  Learn more about [filters in API Query Language](https://dev.wix.com/docs/rest/articles/get-started/api-query-language.md#filters).  > **Note:** The values you provide for each filter field must adhere to that field's data type. For example, when filtering by a field whose type is Date and Time, use an object in the following format: `"someDateAndTimeFieldKey": { "$date": "YYYY-MM-DDTHH:mm:ss.sssZ"}`. Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/data-types-in-wix-data.md).  
              - name: sort | type: Sorting | description: Sorting preferences.  Learn more about [sorting and paging](https://dev.wix.com/docs/rest/articles/get-started/sorting-and-paging.md).  
                 - name: values | type: array<Sorting> | description: Fields to sort the results by.  | validation: maxItems 1000
                    - name: fieldName | type: string | description: Name of the field to sort by.  | validation: minLength 1, maxLength 1000
                    - name: order | type: SortOrder | description: Sort order.  
                             - enum: ASC, DESC
              - name: projection | type: Projection | description: Transforms items by including, excluding, or reshaping fields.  
                 - name: fields | type: array<Field> | description: Fields to include, exclude, or reshape.  | validation: maxItems 1000
                    - ONE-OF: 
                       - name: include | type: Include | description: When specified, includes only the specified field in the result. All other fields are excluded.  
                          - name: fieldName | type: string | description: Key of the field to include in the result.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                       - name: exclude | type: Exclude | description: When specified, excludes the specified field from the result. All other fields are included.  
                          - name: fieldName | type: string | description: Key of the field to exclude from the result.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                       - name: reshape | type: Reshape | description: Reshapes a new field based on the specified expression. The field used by the expression is not included in the result.  
                          - name: resultFieldName | type: string | description: Key of the field to create in the result item.  Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                          - name: expression | type: Expression | description: Expression to resolve. The result of the expression becomes the value of the new field.  
                       - name: projectNested | type: ProjectNested | description: Creates nested fields by including, excluding, or reshaping fields.  
                          - name: resultFieldName | type: string | description: Key of the parent field for the nested fields.  Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                          - name: fields | type: array<Field> | description: Nested fields to include, exclude, or reshape.  | validation: maxItems 1000
              - name: objectToArray | type: ObjectToArray | description: Transforms an object into an array where each object property becomes a new array element containing the property's key and value, as well as all other properties from the original object.  
                 - name: objectFieldName | type: string | description: Key of the object field to convert to an array.  Use dot notation to specify nested fields. For example, `user.name` or `product.price`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
                 - name: destinationFieldName | type: string | description: Key of the new array to create in the result item.  Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
              - name: unwindArray | type: UnwindArray | description: Creates a result item for each array element. Each result contains the full original item, with the array field replaced by an element whose key is the array name and whose value is the array element.  
                 - name: arrayFieldName | type: string | description: Key of the array field to unwind.  Use dot notation to specify a nested array. For example, `user.products` or `product.colors`. Learn more about [field keys](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-id-velo-by-wix-only).  | validation: maxLength 1000
              - name: skip | type: integer | description: Number of results to skip from the beginning of the result set.  
              - name: limit | type: integer | description: Maximum number of results to return.  
              - name: addFields | type: AddFields | description: Adds or replaces fields in each result item.  
                 - name: fields | type: array<AddField> | description: Fields to add or replace in the result items.  | validation: maxItems 1000
                    - name: fieldName | type: string | description: Key of the field to add or replace in the result item.  | validation: maxLength 1000
                    - name: expression | type: Expression | description: Expression to resolve. The result of the expression becomes the value of the field.  
              - name: lookup | type: Lookup | description: Joins items from another collection into an array field by matching a local field against a foreign field.  
                 - name: dataCollectionId | type: string | description: GUID of the collection to join with.  | validation: maxLength 256
                 - name: localField | type: string | description: Key of the local field whose value is used for matching items in the joined collection.  | validation: maxLength 1000
                 - name: foreignField | type: string | description: Key of the field in the joined collection to match against the local field value.  | validation: maxLength 1000
                 - name: asField | type: string | description: Key of the array field where matching joined items are stored.  | validation: maxLength 1000
              - name: unionWith | type: UnionWith | description: Appends results from another collection pipeline to the current results.  
                 - name: dataCollectionId | type: string | description: GUID of the collection whose results are appended to the current pipeline results.  | validation: maxLength 256
                 - name: pipeline | type: AggregationPipeline | description: Pipeline to run on the union collection before appending its results.  
                    - ONE-OF: 
                    - name: stages | type: array<Stage> | description: Sequence of aggregation operations to apply to the data.  Stages are processed in order, with each stage operating on the output of the previous stage.  | validation: maxItems 100
   param name: options | type: WixDataAggregateOptions  none  
        - name: suppressHooks | type: boolean | description: Prevents hooks from running for the operation. Can only be used in the [backend code of a Wix site](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/backend-code/about-the-site-backend.md).  
        - name: showDrafts | type: boolean | description: When `true`, operations include draft items. Read operations include draft items in their response, and write operations modify draft items. Default: `false`.  
        - name: appOptions | type: object | description: Options for [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md).  
        - name: language | type: string | description: Language to translate result text into, in [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. If provided, the result text is returned in the specified language. If not provided, the result text is not translated.  > **Note:** Translation for the specified language must be enabled for the collection in [Wix Multilingual](https://www.wix.com/app-market/wix-multilingual).  
        - name: consistentRead | type: boolean | description: When `true`, reads data from the primary database instance. This decreases performance but ensures data retrieved is up-to-date even immediately after an update. Learn more about [Wix Data and eventual consistency](https://dev.wix.com/docs/sdk/backend-modules/data/eventual-consistency.md).  
        - name: returnTotalCount | type: boolean | description: When `true`, the query results include a `totalCount` and `totalPages` properties containing the totals of items matching query. Requesting total count slows down the query.  Default: `false`  
 Return type: PROMISE<AggregatePipelineDataItemsResponse>
  - name: results | type: array | description: Aggregation results.  | validation: maxItems 10000
  - name: pagingMetadata | type: PagingMetadataV2 | description: Paging information.  
     - name: count | type: integer | description: Number of items returned in the response.  | validation: format int32
     - name: offset | type: integer | description: Offset that was requested.  | validation: format int32
     - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used, `returnTotalCount` is `true` in the request, and `tooManyToCount` is false.  | validation: format int32
     - name: tooManyToCount | type: boolean | description: Whether the server failed to calculate the `total` field.  
     - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used.  
        - name: next | type: string | description: Cursor pointing to next page in the list of results.  | validation: maxLength 150000
        - name: prev | type: string | description: Cursor pointing to previous page in the list of results.  | validation: maxLength 150000


```

### Examples

### aggregatePipeline
```javascript
import { items } from '@wix/data';

async function aggregatePipeline(dataCollectionId,pipeline,options) {
  const response = await items.aggregatePipeline(dataCollectionId,pipeline,options);
};
```

### aggregatePipeline (with elevated permissions)
```javascript
import { items } from '@wix/data';
import { auth } from '@wix/essentials';

async function myAggregatePipelineMethod(dataCollectionId,pipeline,options) {
  const elevatedAggregatePipeline = auth.elevate(items.aggregatePipeline);
  const response = await elevatedAggregatePipeline(dataCollectionId,pipeline,options);
}
```

### aggregatePipeline (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { items } from '@wix/data';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { items },
  // Include the auth strategy and host as relevant
});


async function aggregatePipeline(dataCollectionId,pipeline,options) {
  const response = await myWixClient.items.aggregatePipeline(dataCollectionId,pipeline,options);
};
```

---