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

WeChat small program cloud development API database update records


May 20, 2021 WeChat Mini Program Development Document



databaseUpdate

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

The database updates the record

The request address

POST https://api.weixin.qq.com/tcb/databaseupdate?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 illustrate
errcode number error code
errmsg string Error message
matched number Update condition matches the result number
modified number Modified record number, Note: Use the SET to operate the newly inserted data is not included in the number of modifications
id string Newly inserted ID, Note: This field will be valued only when using the set operation.

Errcode's legitimate value

value illustrate Minimum version
0 Request success
-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 Error
85088 The APP has not opened the cloud development
Other error code Cloud development error code

Request Data Example 1: Operation Collection

{
  "env":"test2-4a89da",
  "query": "db.collection(\"geo\").where({age:14}).update({data:{age: _.inc(1)}})"
}

Return Data Example 1: Operation Collection

{
    "errcode": 0,
    "errmsg": "ok",
    "matched": 1,
    "modified": 1,
    "id": ""
}

Request data Example 2: Update a record

{
  "env":"test2-4a89da",
  "query": "db.collection(\"geo\").doc(\"56abd6d5-9daf-4fc7-af05-eca13933f1aa\").update({data:{age: 10}})"
}

Return data Example 2: Update a record

{
    "errcode": 0,
    "errmsg": "ok",
    "matched": 1,
    "modified": 1,
    "id": ""
}

Request data Example 3: Update to replace a record

{
  "env":"test2-4a89da",
  "query": "db.collection(\"geo\").doc(\"be62d9c4-43ec-4dc6-8ca1-30b206eeed24\").set({data: {
        description: \"set\",
        done: true
      }})"
}

Return Data Example 3: Update to replace a record

{
    "errcode": 0,
    "errmsg": "ok",
    "matched": 0,
    "modified": 0,
    "id": "be62d9c4-43ec-4dc6-8ca1-30b206eeed24"
}

Description of the database action statement

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