This API should be called on the server side. For detailed instructions, refer to Server API.
Insert a record into the database.
Request URL
POST https://api.weixin.qq.com/tcb/databaseadd?access_token=ACCESS_TOKEN
Request Parameters
| Attribute | Type | Default | Required | Description |
|---|---|---|---|---|
| access_token / cloudbase_access_token | string | Yes | API call credential | |
| env | string | Yes | Cloud Environment ID | |
| query | string | Yes | Database operation statement |
Return Value
Object
The returned JSON data packet
| Property | Type | Description |
|---|---|---|
| errcode | number | Error code |
| errmsg | string | Error message |
| id_list | Array.<string> | Primary key _id of the successfully inserted data set. |
Legal values for errcode
| Value | Description | Minimum version |
|---|---|---|
| 0 | Request successful | |
| -1 | System error | |
| -1000 | System error | |
| 40014 | Invalid AccessToken | |
| 40097 | Invalid request parameters | |
| 40101 | Missing required parameters | |
| 41001 | Missing AccessToken | |
| 42001 | AccessToken expired | |
| 43002 | HTTP METHOD error | |
| 44002 | POST BODY is empty | |
| 47001 | POST BODY format error | |
| 85088 | Cloud development is not enabled for this APP | |
| Other error codes | Cloud development error codes |
Request Data Example
{
"env":"test2-4a89da",
"query": "db.collection(\"geo\").add({
data: [{
description: \"item1\",
due: new Date(\"2019-09-09\"),
tags: [
\"cloud\",
\"database\"
],
location: new db.Geo.Point(113, 23),
done: false
},
{
description: \"item2\",
due: new Date(\"2019-09-09\"),
tags: [
\"cloud\",
\"database\"
],
location: new db.Geo.Point(113, 23),
done: false
}
]
})"
}
Response Data Example
{
"errcode": 0,
"errmsg": "ok",
"id_list": [
"be62d9c4-43ec-4dc6-8ca1-30b206eeed24",
"0f4b8add5cdd728a003bf5c83ed99dff"
]
}
Description of Database Operation Statements
The syntax of database operation statements is the same as that of the Database API.