# 数据库集合管理
接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南
接口英文名:dbcollectionManage
数据库集合管理
# 1. 调用方式
# HTTPS 调用
POST https://api.weixin.qq.com/componenttcb/dbcollection?access_token=ACCESS_TOKEN
# 云调用
- 本接口不支持云调用
# 第三方调用
- 本接口仅支持第三方平台使用 component_access_token 自己调用。
# 2. 请求参数
# 查询参数 Query String parameters
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| access_token | string | 是 | 接口调用凭证,可使用 component_access_token |
# 请求体 Request Payload
| 参数名 | 类型 | 必填 | 说明 | 枚举 |
|---|---|---|---|---|
| env | string | 是 | 环境ID | - |
| limit | number | 否 | 返回数据长度。get时选填 | - |
| offset | number | 否 | 数据偏移量。get时选填 | - |
| action | string | 是 | 操作类型 | 枚举值 |
| collection_name | string | 是 | 集合名称。add、del时必填 | - |
# 3. 返回参数
# 返回体 Response Payload
| 参数名 | 类型 | 说明 |
|---|---|---|
| errcode | number | 错误码 |
| errmsg | string | 错误信息 |
| collections | objarray | 集合信息。get时返回 |
| total | number | 页面信息。get时返回 |
# Res.collections(Array) Object Payload
集合信息。get时返回
| 参数名 | 类型 | 说明 |
|---|---|---|
| name | string | 集合名 |
| count | number | 表中文档数量 |
| size | number | 表的大小(即表中文档总大小),单位:字节 |
| index_count | number | 索引数量 |
| index_size | number | 索引占用大小,单位:字节 |
# 4. 枚举信息
# Body.action Enum
操作类型
| 枚举值 | 描述 |
|---|---|
| get | 查询 |
| add | 增加 |
| del | 删除 |
# 5. 注意事项
本接口无特殊注意事项
# 6. 代码示例
# 5.1 数据库增加集合
请求示例
{
"env": "dev-3gewtf9c10f60c76",
"collection_name": "testcollection"
}
返回示例
{
"errcode": 0,
"errmsg": "ok",
}
# 5.2 数据库查询集合
请求示例
{
"env": "test-env1"
}
返回示例
{
"errcode": 0,
"errmsg": "ok",
"collections": [
{
"name": "testcollection",
"count": 0,
"size": 0,
"index_count": 2,
"index_size": 8192
}
],
"total": 1
}
# 5.3 数据库删除集合
请求示例
{
"env": "dev-3gewtf9c10f60c76",
"collection_name": "testcollection"
}
返回示例
{
"errcode": 0,
"errmsg": "ok",
}
# 7. 错误码
以下是本接口的错误码列表,其他错误码可参考 通用错误码;调用接口遇到报错,可使用官方提供的 API 诊断工具 辅助定位和分析问题。
| 错误码 | 错误描述 | 解决方案 |
|---|---|---|
| -1000 | system error | 系统错误 |
| -1 | system error | 系统繁忙,此时请开发者稍候再试 |
| 0 | ok | ok |
| 40014 | invalid access_token | 不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口 |
| 40097 | invalid args | 参数错误 |
| 40101 | missing parameter | 缺少必填参数 |
| 41001 | access_token missing | 缺少 access_token 参数 |
| 42001 | access_token expired | access_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明 |
| 43002 | require POST method | 需要 POST 请求 |
| 44002 | empty post data | POST 的数据包为空。post请求body参数不能为空。 |
| 47001 | data format error | 解析 JSON/XML 内容错误;post 数据中参数缺失;检查修正后重试。 |
| 85088 | no qbase privilege | 该APP未开通云开发 |
# 8. 适用范围
本接口支持「第三方平台」账号类型代调用,权限集请参考「调用方式」部分。其他账号类型如无特殊说明,均不可调用。