---
title: "Aggregate Documents"
method: POST
path: "/action/aggregate"
---

# Aggregate Documents

`POST /action/aggregate`

Run an aggregation pipeline.

## Request body

- AggregateRequestBody
  - `dataSource` string, required — The name of a linked MongoDB Atlas data source. This is commonly `"mongodb-atlas"` though it may be different in your App if you chose a different name when you created the data source.
  - `database` string, required — The name of a database in the specified data source.
  - `collection` string, required — The name of a collection in the specified database.
  - `pipeline` object[], required — An array of aggregation stages.

## Response `200`

Success

- AggregateResponseBody
  - `documents` object[], required — An array that contains the result set of the aggregation.

## Other responses

- `400` — The request was malformed or incomplete.
- `401` — The authenticated user does not have permission to access this endpoint.

---

[API](https://skmtc.net/ferretdb/apis/ferretdb-data-api.md) · [All operations](https://skmtc.net/ferretdb/apis/ferretdb-data-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/ferretdb/ferretdb-data-api/versions/6fcb7dd3fcd6/schema)
