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

# Create an aggregate

**Where:** Database → Aggregates → New · `/projects/<project>/db/aggregates/new`

{% hint style="info" %}
Screenshot TODO — capture comes from testing-plan area **04-taxonomies**.
{% endhint %}

## Fields

* **Schema** (required) — the collection the pipeline runs on. Picking one shows a **Sample record** panel with the first record from that collection, so you can see the field names you are aggregating.
* **Name** (required) and **Description**.
* The **pipeline editor** — standard MongoDB stages as JSON. Strict JSON validation is off on purpose: you may embed tokens that start with `@Model`, e.g. `{ "$match": { "birthDate": { "$gt": @Model.userBirthday } } }`, and pass the values at execution time.
* **TEST** — runs the pipeline against live data and shows the response as an expandable JSON tree. When the pipeline contains `@Model` tokens, a modal first asks for a test value per token.

Example pipeline — paid orders per customer, biggest spenders first:

```json
[
  { "$match": { "status": "paid" } },
  { "$group": { "_id": "$customerId", "orders": { "$sum": 1 }, "total": { "$sum": "$amount" } } },
  { "$sort": { "total": -1 } }
]
```

**Save** stores the aggregate and returns to the list; it gets an id (`maggr_…`) your app calls with `executeAggregate`. **Create using AI Chat** opens the assistant, which reads your schema fields, drafts the pipeline into this editor, and leaves saving to you.

## Use it from code

[Database → Aggregates](/sdks-and-cli/database/aggregates.md)

## API reference

Endpoints: [Save Database Aggregate](/api-reference/database/aggregates/save-database-aggregate.md), [Test Database Aggregate](/api-reference/database/aggregates/test-database-aggregate.md), [Execute Aggregate](/api-reference/database/collections/execute-aggregate.md).
