# databaseUpdate

Call this API at the server side. For more information, see Server API.

Updates records in database.

# Request Address

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

# Request Parameters

Attribute Type Default Required Description
access_token string Yes Credentials to call API
env string Yes Cloud environment ID
query string Yes Database operation statement

# Return Value

# Object

JSON data package that is returned

Attribute Type Description
errcode number Error code
errmsg string Error message
matched number Number of results matched to update conditions
modified number Number of modified records. Note: Modifying new data by performing the set operation is not counted
id string ID of a new record. Note: This field has a value only when updating new data by performing the set operation.

Valid values of errcode

Value Description Minimum Version
0 Request successful
-1 System Error
-1000 System Error
40014 Invalid AccessToken
40097 Invalid request parameter
40101 Required parameter missing
41001 AccessToken missing
42001 AccessToken expired
43002 HTTP METHOD error
44002 Empty POST BODY
47001 Incorrect format of POST BODY
85088 Cloud Base is not enabled on this App
Other error codes Cloud Base error codes

# 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 and 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 and Replace a Record

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

# Description of Database Operation Statements

Database operation statements use the same syntax with Database APIs