curl --request POST \
--url https://api.example.com/{collection}/aggregate \
--header 'Content-Type: application/json' \
--data '
{
"pipeline": [
{}
]
}
'{
"data": [
{}
],
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
}
}Execute MongoDB aggregation pipelines with automatic RBAC enforcement
curl --request POST \
--url https://api.example.com/{collection}/aggregate \
--header 'Content-Type: application/json' \
--data '
{
"pipeline": [
{}
]
}
'{
"data": [
{}
],
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
}
}Documentation Index
Fetch the complete documentation index at: https://mintlify.com/KTS-o7/permission-mongo/llms.txt
Use this file to discover all available pages before exploring further.
{
"pipeline": [
{
"$match": {
"status": "active"
}
},
{
"$group": {
"_id": "$department",
"count": { "$sum": 1 },
"avg_salary": { "$avg": "$salary" }
}
},
{
"$sort": { "count": -1 }
}
]
}
{
"pipeline": [
{
"$match": {
"created_at": {
"$gte": "2024-01-01T00:00:00Z"
}
}
},
{
"$lookup": {
"from": "departments",
"localField": "department_id",
"foreignField": "_id",
"as": "department"
}
},
{
"$unwind": "$department"
},
{
"$group": {
"_id": {
"department": "$department.name",
"month": { "$month": "$created_at" }
},
"total_sales": { "$sum": "$amount" },
"order_count": { "$sum": 1 }
}
},
{
"$project": {
"_id": 0,
"department": "$_id.department",
"month": "$_id.month",
"total_sales": 1,
"order_count": 1,
"avg_order_value": {
"$divide": ["$total_sales", "$order_count"]
}
}
}
]
}
$group and $project operations.{
"data": [
{
"_id": "Engineering",
"count": 45,
"avg_salary": 95000
},
{
"_id": "Product",
"count": 23,
"avg_salary": 88000
},
{
"_id": "Sales",
"count": 18,
"avg_salary": 75000
}
]
}
{
"$match": {
"status": "active",
"age": { "$gte": 18 }
}
}
{
"$group": {
"_id": "$category",
"total": { "$sum": "$amount" },
"count": { "$sum": 1 },
"avg": { "$avg": "$amount" },
"max": { "$max": "$amount" },
"min": { "$min": "$amount" }
}
}
$sum: Calculate sum$avg: Calculate average$min, $max: Find minimum/maximum$first, $last: Get first/last value$push: Build array of values$addToSet: Build array of unique values{
"$project": {
"_id": 0,
"name": 1,
"full_name": {
"$concat": ["$first_name", " ", "$last_name"]
},
"age_group": {
"$cond": [
{ "$gte": ["$age", 18] },
"adult",
"minor"
]
}
}
}
{
"$sort": {
"created_at": -1,
"name": 1
}
}
{
"$limit": 100
}
{
"$skip": 20
}
{
"$lookup": {
"from": "orders",
"localField": "_id",
"foreignField": "user_id",
"as": "user_orders"
}
}
{
"$unwind": "$items"
}
{
"$addFields": {
"total_price": {
"$multiply": ["$quantity", "$unit_price"]
}
}
}
handlers_query.go:353-388:
The aggregation pipeline is automatically enhanced with RBAC filters:
$match stage with RBAC filters is prepended to the pipeline$match, the RBAC filter is merged with it// Example: RBAC filter is automatically added
// User's pipeline:
[
{ "$group": { "_id": "$department", "count": { "$sum": 1 } } }
]
// Actual executed pipeline:
[
{ "$match": { "tenant_id": "user-tenant-123" } }, // RBAC filter
{ "$group": { "_id": "$department", "count": { "$sum": 1 } } }
]
handlers_query.go:345-351:
scalability.max_aggregation_stages)handlers_query.go:404-410:
scalability.max_result_size){
"pipeline": [
{
"$match": {
"order_date": {
"$gte": "2024-01-01T00:00:00Z",
"$lt": "2024-12-31T23:59:59Z"
}
}
},
{
"$group": {
"_id": {
"year": { "$year": "$order_date" },
"month": { "$month": "$order_date" }
},
"revenue": { "$sum": "$total_amount" },
"orders": { "$sum": 1 }
}
},
{
"$sort": { "_id.year": 1, "_id.month": 1 }
}
]
}
{
"pipeline": [
{
"$match": {
"last_login": { "$exists": true }
}
},
{
"$group": {
"_id": {
"$cond": [
{ "$gte": ["$last_login", { "$subtract": [new Date(), 7*24*60*60*1000] }] },
"active",
"inactive"
]
},
"count": { "$sum": 1 }
}
}
]
}
{
"pipeline": [
{
"$match": { "status": "active" }
},
{
"$group": {
"_id": "$sales_rep_id",
"total_sales": { "$sum": "$amount" },
"deals_closed": { "$sum": 1 }
}
},
{
"$sort": { "total_sales": -1 }
},
{
"$limit": 10
},
{
"$lookup": {
"from": "users",
"localField": "_id",
"foreignField": "_id",
"as": "rep"
}
},
{
"$unwind": "$rep"
},
{
"$project": {
"name": "$rep.name",
"total_sales": 1,
"deals_closed": 1
}
}
]
}
collection_not_found: Collection does not existforbidden: User lacks aggregate permissionbad_request: Invalid pipeline (too many stages, invalid syntax)internal_error: Aggregation execution failed{
"error": {
"code": "bad_request",
"message": "Aggregation pipeline exceeds maximum allowed stages",
"details": {
"max_stages": 20,
"actual_stages": 25
}
}
}
{
"error": {
"code": "bad_request",
"message": "Aggregation result exceeds maximum allowed size",
"details": {
"max_size": 10000,
"actual_size": 15000
}
}
}
$match and $sort are indexed$limit as soon as possible if you don’t need all resultspkg/api/handlers_query.go:299-420