Skip to content

Spatial Data Delete API

There are two way to delete a spatial value from an object in the database:

  1. Using Backendless Console
  2. Using API

Deleting Data with Console

To delete a spatial value in console, simply clear out the contents of a cell and press Enter. Backendless Console confirms that the object has been updated:

record-updated-point-deleted

Deleting Data with the API

Deleting a spatial value from an object using the API is technically the object update operation with the spatial value property set to null. The following algorithm can be used to perform deletion:

  1. Retrieve from the database the data object which contains the spatial property to be deleted.
  2. Set the property value to null.
  3. Save the object back in the database.

The example below demonstrates the approach:

Backendless.Data.Of( "Person" ).FindFirst( new AsyncCallback<Dictionary<String, Object>>(
firstPerson=>
{
  firstPerson[ "location" ] = null;
  Backendless.Data.Of( "Person" ).Save( firstPerson, new AsyncCallback<Dictionary<String, Object>>(
  response=>
  {
    //location has been deleted
  },
  fault=>
  {
    //an error has occurred
  }));
},
fault=>
{
  //an error has occurred
}));

Person class:

using BackendlessAPI;

public class Person
{
  public Point Location {get;set;}
}
Code to delete location in a Person object:
Backendless.Data.Of<Person>().FindFirst( new AsyncCallback<Person>(
firstPerson=>
{
  firstPerson.Location = null;
  Backendless.Data.Of<Person>().Save( firstPerson, new AsyncCallback<Person>(
  {
    //location has been deleted
  },
  error=>
  {
    //an error has occurred
  }));
},
fault=>
{
  //an error has occurred
}));

Alternatively, the same result can be achieved using the bulk update API operation. With this approach you can delete a spatial property either in a single or multiple objects. This is done with a query (the where clause) used in the API request. For example, the following query uniquely identifies a single object: objectId = 'XXX-XXX-XXX'. Consider an example demonstrating the approach:

String whereClause = "email = 'bob@thebuilder.com'";
Dictionary<String, Object> changes = new Dictionary<String, Object>();
changes[ "location" ] = null;

Backendless.Data.Of( "Person" ).Update( whereClause, changes, new AsyncCallback<int>(
objectsUpdated =>
{
  // objectsUpdated is how many objects were updated by the API call
},
fault =>
{ 
  // an error has occurred
}));

Codeless Reference

Consider the following records stored in the data table called geolocation:

data_spatial_update_2

Suppose you need to remove the geolocation data from the record, while leaving the value in the location column "blank". Note, that when there is no value in the column and it is "blank", the column actually contains the null value. So to delete the contents of the record, we must update the value in a specific column to the null. The example below "deletes" the current geolocation  data only for one object.

data_spatial_update_1

where:

Argument                Description
table name Name of the data table where a new record must be deleted(updated).
object An object to save in the database. Object properties must match the names of the table columns.
return result Optional parameter. When this box is checked, the operation returns the deleted(updated) object with the objectId property.

After the operation runs, the value gets deleted(replaced with the null value).

data_spatial_update_3

To delete geolocation data for multiple records, you have to use the Bulk Update Codeless block. In this case you must establish the where clause condition to allow the operation to find objects that must be delete(updated). As it was described above, the deletion result is achieved when a column is updated with the null value. The null indicates that a specific column contains no value.

The example below deletes the geolocation data for two objects in the data table. The where clause property contains the following condition:

objectId = 'E0236915-54CE-45DE-AC65-6F2093AC6ADF' OR objectId = 'F77A8ACE-EF6E-405F-9B31-E495E897D0D6'

As you can see, we have to reference two objectId values and also use the OR operator.

data_spatial_update_4

where:

Argument                Description
table name Name of the data table where records must be deleted(updated).
where clause A condition which references a column name and a specific value in the data table where an update/deletion has to be carried out. Refer to the Search With The Where Clause topic for more information.
changes This parameter expects an object that must contain the name of the column and a new value to update the existing contents with.
Return count of updated objects Optional parameter. When this box is checked, the operation returns the number of deleted(updated) objects.

The operation has successfully deleted(updated) the contents in the location column for two objects.

data_spatial_update_5