| title | Aggregate Data |
|---|---|
| description | Execute MongoDB aggregation pipelines on your collection. |
Runs a MongoDB aggregation pipeline on the specified collection. This allows for complex data processing, grouping, and transformations.
x-api-key: your pk_live_… or sk_live_… key.
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.
const res = await fetch(
'https://api.urbackend.in/api/data/orders/aggregate',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'pk_live_YOUR_KEY'
},
body: JSON.stringify({
pipeline: [
{ $match: { status: 'completed' } },
{ $group: { _id: '$customerId', totalAmount: { $sum: '$amount' } } },
{ $sort: { totalAmount: -1 } }
]
})
}
);
const { success, data } = await res.json();curl -X POST "https://api.urbackend.in/api/data/orders/aggregate?include_deleted=false" \
-H "Content-Type: application/json" \
-H "x-api-key: pk_live_YOUR_KEY" \
-d '{
"pipeline": [
{ "$group": { "_id": "$category", "count": { "$sum": 1 } } }
]
}'{
"success": true,
"data": [
{ "_id": "electronics", "count": 42 },
{ "_id": "books", "count": 12 }
],
"message": "Aggregation executed successfully."
}| Status | Cause |
|---|---|
400 Bad Request |
Invalid pipeline syntax or blocked stage used |
401 Unauthorized |
Missing or invalid API key |
404 Not Found |
Collection does not exist |