> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/api-reference/database/aggregates/save-database-aggregate.md).

# Save Database Aggregate

Creates or updates a saved Mongo aggregation.

An **aggregate** is a saved MongoDB aggregation pipeline you can run to compute, group, and summarise data.

This endpoint creates the database aggregate and returns its id.

Saving reads the pipeline and stores the collections it joins (`$lookup`, `$graphLookup`, `$unionWith`, nested pipelines, `$facet`) in `JoinedCollections` on the aggregate. A pipeline with `$out`, `$merge`, `$where`, `$function` or `$accumulator` is refused with `CM-ERRORS-DATABASE-031`; a join into another database with `CM-ERRORS-DATABASE-034`.

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/aggregates" method="post" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

## In Cloud

Manage this visually in Cloud — see [Database](/codemash/cloud/database/aggregates.md).

## Use it from code

Every Norbix SDK exposes this endpoint as a method — see [Save Database Aggregate](/codemash/sdks/database/aggregates/save-database-aggregate.md) in the SDK reference, with examples in every language.
