Skip to content

Upsert Multiple Objects

Description

This operation creates and/or updates multiple objects in the database. The operation receives a collection of objects as the argument. For every object in the collection it checks if an object already exists in the database and in that case updates it with the property values in the object. Otherwise, the object is saved in the database. To check if an object exists in the database, Backendless uses the value of the objectId property.

Method

Backendless.Data.bulkUpsert(objects: Array<object>): Promise<Array<string>>;

where:

Argument                Description
objects Required parameter.An array of objects to upsert.

Return Value

An array of the objectId values of updated or inserted objects.

Example

The example below upserts two objects in the "Person" data table.

Backendless.Data.bulkUpsert([{"objectId":"297BEFCD-2992-4724-8AAC-F3EB00E413D2", "email":"alice@yourmail.com", "age":25}, {"objectId":"8CCC0E0C-C1AB-4B29-B632-821A00863FA7", "email":"peter@yourmail.com", "age":60}])
.then(ids=>console.log(ids))
.catch(error=>console.error(error))

Codeless Reference

data_api_bulk_upsert_1

where:

Argument                Description
table name Name of the data table where the operation inserts and/or updates objects.
objects A list of objects to update or create.
return upserted objectIds When this box is checked, the operation returns a list of objectId values of updated or inserted objects.

Returns a list containing objectId values of updated or inserted objects.

Consider the following records in the Person data table:

data_api_bulk_upsert_2

The example below updates two objects in the Person data table:

data_api_bulk_upsert_3

The output will look as shown below after the Codeless logic runs. Values in the "age" and "email" columns were modified.

data_api_bulk_upsert_4

The operation returns the array of objectId values:

data_api_bulk_upsert_5