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()
 .then(firstPerson => {
   firstPerson.location = null

   return Backendless.Data.of('Person').save(firstPerson)
 })
 .then(response => {
   // location has been deleted
 })
 .catch(error => {
   // an error has occurred
 })
Person class:
class Person {
 constructor() {
   this.location = null
 }

 getLocation() {
   return this.location
 }

 setLocation(location) {
   this.location = location
 }
}
Code to delete location in a Person object:
Backendless.Data.mapTableToClass('Person', Person)

Backendless.Data.of(Person).findFirst()
 .then(firstPerson => {
   firstPerson.setLocation(null)

   return Backendless.Data.of(Person).save(firstPerson)
 })
 .then(response => {
   // location has been deleted
 })
 .catch(error => {
   // 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:

const whereClause = 'email = \'bob@thebuilder.com\''
const changes = {
 location: null
}

Backendless.Data.of('Person').bulkUpdate(whereClause, changes)
 .then(objectsUpdated => {
   console.log(objectsUpdated)
   // objectsUpdated is how many objects were updated by the API call
 })
 .catch(error => {
   console.log(error)
   // an error has occurred
 })