curl --request POST \
--url https://api.example.com/{collection}/count \
--header 'Content-Type: application/json' \
--data '{
"filter": {}
}'{
"data": {
"count": 123
},
"error": {
"code": "<string>",
"message": "<string>",
"details": {}
}
}Count documents matching a filter query with RBAC enforcement
curl --request POST \
--url https://api.example.com/{collection}/count \
--header 'Content-Type: application/json' \
--data '{
"filter": {}
}'{
"data": {
"count": 123
},
"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.
POST /users/count
{
"filter": {
"status": "active",
"department": "Engineering"
}
}
{
"filter": {
"created_at": {
"$gte": "2024-01-01T00:00:00Z",
"$lt": "2024-12-31T23:59:59Z"
},
"age": { "$gte": 18 },
"role": { "$in": ["developer", "designer", "manager"] },
"email_verified": true
}
}
{
"data": {
"count": 142
}
}
filter parameter supports MongoDB query operators:
{
"filter": {
"age": { "$gte": 18, "$lt": 65 },
"salary": { "$gt": 50000 },
"status": { "$ne": "deleted" }
}
}
$eq: Equal to$ne: Not equal to$gt: Greater than$gte: Greater than or equal to$lt: Less than$lte: Less than or equal to{
"filter": {
"role": { "$in": ["admin", "moderator"] },
"status": { "$nin": ["banned", "suspended"] }
}
}
$in: Value is in array$nin: Value is not in array{
"filter": {
"$or": [
{ "status": "active" },
{ "last_login": { "$gte": "2024-01-01T00:00:00Z" } }
],
"department": { "$exists": true }
}
}
$and: All conditions must match$or: At least one condition must match$not: Inverts the condition$exists: Field exists/doesn’t exist{
"filter": {
"email": { "$regex": "@company\\.com$" }
}
}
handlers_query.go:470-477:
The count operation automatically combines the provided filter with RBAC query filters. This ensures users only count documents they have permission to read.
rbacFilter := h.getRBACQueryFilter(authCtx, collection, schema.ActionRead)
combinedFilter := h.combineFilters(request.Filter, rbacFilter)
// Count documents before batch delete
POST /products/count
{
"filter": {
"status": "discontinued",
"stock": 0
}
}
// Response: { "data": { "count": 47 } }
// Now you know 47 documents will be deleted
// Count active users by department
POST /users/count
{
"filter": {
"status": "active",
"department": "Engineering"
}
}
// Verify how many documents will be affected
POST /orders/count
{
"filter": {
"status": "pending",
"created_at": { "$lt": "2024-01-01T00:00:00Z" }
}
}
{
"error": {
"code": "bad_request",
"message": "Invalid JSON body",
"details": {
"error": "unexpected end of JSON input"
}
}
}
handlers_query.go:492-493
pkg/api/handlers_query.go:422-502