# databaseAggregate

本接口应在服务器端调用,详细说明参见服务端API

数据库聚合

# 请求地址

POST https://api.weixin.qq.com/tcb/databaseaggregate?access_token=ACCESS_TOKEN

# 请求参数

属性 类型 默认值 必填 说明
access_token / cloudbase_access_token string 接口调用凭证
env string 云环境ID
Query string 数据库操作语句

# 返回值

# Object

返回的 JSON 数据包

属性 类型 说明
errcode number 错误码
errmsg string 错误信息
data Array.<string> 记录数组

errcode 的合法值

说明 最低版本
0 请求成功
-1 系统错误
-1000 系统错误
40014 AccessToken 不合法
40097 请求参数错误
40101 缺少必填参数
41001 缺少AccessToken
42001 AccessToken过期
43002 HTTP METHOD 错误
44002 POST BODY 为空
47001 POST BODY 格式错误
85088 该APP未开通云开发
其他错误码 云开发错误码

# 请求数据示例

{
  "env":"test2-4a89da",
  "query": "db.collection(\"test_collection\").aggregate().match({tags:\"cloud\"}).limit(10).end()"
}

# 返回数据示例

{
    "errcode": 0,
    "errmsg": "ok",
    "data": [
    "{\"_id\":\"f77e039f-f1cf-4aa8-bd59-16cbaa91e6ea\",\"location\":{\"type\":\"Point\",\"coordinates\":[{\"$numberDouble\":\"113.0\"},{\"$numberDouble\":\"23.0\"}]},\"done\":false,\"description\":\"learn cloud database\",\"due\":\"2019-09-09\",\"tags\":[\"cloud\",\"database\"]}",
        "{\"_id\":\"6bb88938-49ea-42b6-a6f5-ce408970cfc6\",\"due\":\"2019-09-09\",\"tags\":[\"cloud\",\"database\"],\"location\":{\"type\":\"Point\",\"coordinates\":[{\"$numberDouble\":\"113.0\"},{\"$numberDouble\":\"23.0\"}]},\"done\":false,\"description\":\"学习 cloud database\"}",
        "{\"_id\":\"51f4f67e-a6a1-4c3e-a50f-827380b8da86\",\"description\":\"学习 cloud database\",\"due\":\"2019-09-09\",\"tags\":[\"cloud\",\"database\"],\"location\":{\"coordinates\":[{\"$numberDouble\":\"113.0\"},{\"$numberDouble\":\"23.0\"}],\"type\":\"Point\"},\"done\":false}",
        "{\"_id\":\"ee1d69da-b7ec-4e7a-bc1f-2fae31da4ce0\",\"tags\":[\"cloud\",\"database\"],\"location\":{\"type\":\"Point\",\"coordinates\":[{\"$numberDouble\":\"113.0\"},{\"$numberDouble\":\"23.0\"}]},\"done\":false,\"description\":\"学习 cloud database\",\"due\":\"2019-09-09\"}"
    ]
}

# 数据库操作语句说明

数据库操作语句语法与数据库 API相同, 聚合操作参考聚合文档