Skip to content

Updating multiple objects

This operation updates one or more objects in a database table. The objects to be updated can be identified with:

  1. objectId values
  2. A query string (a where clause)
  3. Result of a previously ran bulkCreate or object retrieval operation in the same transaction.

To add this operation to a Unit Of Work request, use the following operation in the request payload. The payload are split into categories based on how the the objects are identified in the API:

URL:

POST https://xxxx.backendless.app/api/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "isolationLevelEnum" : "REPEATABLE_READ" | "READ_COMMITTED" | "READ_UNCOMMITTED" | "SERIALZABLE",
  "operations": [
    {
      "operationType": "UPDATE_BULK",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
         "unconditional" : [ "objectId VALUE", "objectId VALUE", "objectId VALUE" ],
         "changes" : { object with key/value changes to apply }
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "UPDATE_BULK" , this designates the operation as "updating multiple objects". The objects to update in the database are defined in the "payload" > "unconditional" property.
"table" The value must contain the name of the table where the objects will be updated.
"opResultId" This is an optional property. If present, must contain an Id for this operation. An operation Id is a free-form string that must be unique within the transaction. If the result of this operation is to be used as an input in another operation within the same transaction, the Id will be used to reference the result.
"payload" > "unconditional" The value is mandatory. Must contain a JSON array. The array contains objectId values identifying the objects which will be updated by this operation.
"payload" > "changes" The value is mandatory. A JSON object containing the changes which will be applied to the objects from the "unconditional" property.

URL:

POST https://xxxx.backendless.app/api/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "isolationLevelEnum" : "REPEATABLE_READ" | "READ_COMMITTED" | "READ_UNCOMMITTED" | "SERIALZABLE",
  "operations": [
    {
      "operationType": "UPDATE_BULK",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
         "conditional" : "where clause query to identify objects",
         "changes" : { object with key/value changes to apply }
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "UPDATE_BULK" , this designates the operation as "updating multiple objects". The objects to update in the database is defined in the "payload" > "unconditional" property.
"table" The value must contain the name of the table where the objects will be updated. The table must exist in the database before the transaction is executed.
"opResultId" This is an optional property. If present, must contain an Id for this operation. An operation Id is a free-form string that must be unique within the transaction. If the result of this operation is to be used as an input in another operation within the same transaction, the Id will be used to reference the result.
"payload" > "conditional" The value is mandatory. Must contain a string value which is a where clause query.The server runs the query in the "table" table to identify the objects which will be updated by this operation.
"payload" > "changes" The value is mandatory. A JSON object containing the changes which will be applied to the objects from the "unconditional" property.

URL:

POST https://api.backendless.com/api/transaction/unit-of-work
Request header:
Content-Type:application/json
Request body:
{
  "isolationLevelEnum" : "REPEATABLE_READ" | "READ_COMMITTED" | "READ_UNCOMMITTED" | "SERIALZABLE",
  "operations": [
    {
      "operationType": "UPDATE_BULK",
      "table": "TABLENAME",
      "opResultId": "OPRESULT-ID",
      "payload": {
         "unconditional" : {
            "___ref":true,
            "opResultId":"OPERATION ID OF FIND OR BULK CREATE OPERATION"
        },
        "changes" : { object with key/value changes to apply }
      }
    }
  ]
}

where:

Argument                Description
"operationType" The value must be "UPDATE_BULK" , this designates the operation as "updating multiple objects". The objects to update in the database is defined in the "payload" > "unconditional" property.
"table" The value must contain the name of the table where the objects will be updated. The table must exist in the database before the transaction is executed.
"opResultId" This is an optional property. If present, must contain an Id for this operation. An operation Id is a free-form string that must be unique within the transaction. If the result of this operation is to be used as an input in another operation within the same transaction, the Id will be used to reference the result.
"payload" > "unconditional" The value is mandatory. Must contain a JSON object with the structure as shown above. The "opResultId" property must contain operation result id of a previous operation in the same transaction. These previous operations can be either Retrieving objects or Saving multiple objects .
"payload" > "changes" The value is mandatory. A JSON object containing the changes which will be applied to the objects from the "unconditional" property.

Return Value

This operation returns the number of updated objects. The returned value can be used in other operations of the same transaction.

Example

Consider the example below. The example adds an operation to update multiple objects in the database. The change is to set the orderStatus property to "completed" for all orders which were delivered. This is the what the data table looks like before the transaction runs:

data-before-bulkupdate.zoom70