Skip to main content

POST /api/data/:collectionName/aggregate

Runs a MongoDB aggregation pipeline on the specified collection. This allows for complex data processing, grouping, and transformations.

Required header

x-api-key: your pk_live_… or sk_live_… key.

Path parameters

string
required
The name of the collection to aggregate.

Query parameters

boolean
If true, includes soft-deleted documents (where isDeleted: true) in the aggregation. Defaults to false.

Request body

array
required
An array of aggregation stages following the standard MongoDB aggregation pipeline syntax.
For security reasons, certain stages like $out and $merge are blocked.

RLS behavior

If Row-Level Security (RLS) is enabled, your backend automatically injects a $match stage at the beginning of your pipeline (or after $geoNear / $search if present). This ensures users only aggregate data they have access to.

Response fields

boolean
true when the aggregation was executed successfully.
array
The results of the aggregation pipeline.
string
Human-readable status message.

Code examples

Success response

Errors