Skip to content

Deleting Multiple Objects

This API deletes multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which deletes all objects in the Person data table where the value of the age property is greater than 20:

Backendless.Data.of( "Person" ).bulkDelete( "age > 20" )
  .then( function( objectsDeleted ) {
    console.log( "Server has deleted " + objectsDeleted + " objects" );
  })
  .catch( function( error ) {
    console.log( "Server reported an error " + error );
  })
Backendless.Data.of(table).bulkDelete(whereClause | data): Promise<string>;
function DataTypeX() {
  this.propertyA = "";
  this.propertyB = "";
}

Backendless.Data.of(DataTypeX).bulkDelete(whereClause | data): Promise<string>;

where:

Argument                Description
table name of the table where the objects will be deleted.
whereClause | data In case you need to delete objects that match a specific criterion, you have to use the whereClause to define a condition, for instance such as "age > 20". Refer to the Search with the Where Clause topic to learn more about ways to obtain objects.

The data property expects an array containing string or number values representing values stored in the objectId column of the data table. Refer to the Data Import topic to learn more about the objectId value as the number.

The data property can also accept an array of objects. Each object must contain the objectId property that can be a string or a number.

The JavaScript representation of possible data types looks as following:

Array<string | number | { objectId: string | number, [key: string]: any }>
DataTypeX function/class identifying the table where the objects will be deleted.

Return Value

The API returns the number of deleted objects.

Codeless Reference

data_service_bulk_delete

where:

Argument                Description
table name Name of the data table where objects will be deleted from.
where clause A condition for selecting objects to be deleted in the data table. Refer to the Search With The Where Clause topic for more information.

Returns the number of deleted objects.

Consider the following records in the employees data table:

data_service_example_delete_object_3

The example below is set to delete all values from the position column that match the where clause condition, (e.g. 'Manager'). In this case, the condition acts like a filter and deletes all values that match the criteria 'Manager'.

data_service_example_bulk_delete

The result of this operation will look as shown below after the Codeless logic runs. As you can see, two records containing the 'Manager' value in the position column were deleted from the data table.

data_service_example_bulk_delete_2

Also, the operation has returned the number 2, indicating the number of deleted objects in the employees data table.

data_service_example_bulk_update_4