Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program cloud development API database insert record


May 20, 2021 WeChat Mini Program Development Document



databaseAdd

This interface should be called on the server side, as detailed in the service side API.

The database inserts records

The request address

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

Request parameters

Property Type The default Required Description
access_token string Is The interface calls the credentials
Env string Is Cloud environment ID
query string Is The database action statement

Returns a value

Object

The returned JSON packet

Property Type Description
errcode number Error code
errmsg string The error message
id_list Array.<string> The primary key of the successfully inserted data collection _id.

The legal value of errcode

Value Description The lowest version
0 The request was successful
-1 System error
-1000 System error
40014 AccessToken is not legal
40097 Request parameter error
40101 Missing required parameters
41001 ACCESSTOKEN
42001 AccessToken expired
43002 HTTP METHOD Error
44002 Post body is empty
47001 POST BODY format is incorrect
85088 The APP is not open for cloud development
Other error codes Cloud development error code

An example of requesting data

{
    "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
      }
      ]
    })"
}

Return an example of the data

{
    "errcode": 0,
    "errmsg": "ok",
    "id_list": [
        "be62d9c4-43ec-4dc6-8ca1-30b206eeed24",
        "0f4b8add5cdd728a003bf5c83ed99dff"
    ]
}

Description of the database action statement

The database action statement syntax is the same as the database API