聚合查询
POST/collections/:collectionName/documents/aggregations
使用 MongoDB 原生聚合管道进行复杂数据分析。支持的聚合阶段包括:$match、$group、$project、$sort、$limit、$skip、$unwind、$lookup(仅管理员权限)、$addFields、$count、$sample、$bucket、$bucketAuto、$geoNear、$replaceRoot、$sortByCount。
自动限制:未指定 $limit 时自动添加 $limit: 20。PRIVATE 权限下自动添加 $match: {_openid: "xxx"}。
Request
Path Parameters
collectionName stringrequired
集合名称
- application/json
Body
required
pipeline object[]required
MongoDB 原生聚合管道数组,每个元素是一个包含单个聚合阶段的 EJSON 对象
Responses
- 200
- 400
聚合查询成功
- application/json
- Schema
- Example (from schema)
- group
- count
Schema
list object[]
聚合结果列表(EJSON 格式)
{
"list": [
{}
]
}
分组统计结果
{
"list": [
{
"_id": "Beijing",
"count": 150
},
{
"_id": "Shanghai",
"count": 120
}
]
}
计数结果
{
"list": [
{
"activeCount": 42
}
]
}
请求参数错误
- application/json
- Schema
- Example (from schema)
Schema
code string
错误码
message string
错误信息
request_id string
请求唯一 ID
{
"code": "INVALID_PARAM",
"message": "param.query can't be empty",
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Loading...