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:

Person class:
import com.backendless.persistence.Point;

public class Person
{
    private Point location;

    public Point getLocation()
    {
        return location;
    }

    public void setLocation( Point location )
    {
        this.location = location;
    }
}
Code to delete location in a Person object:
Backendless.Data.of( Person.class ).findFirst( new AsyncCallback<Person>()
{
    @Override
    public void handleResponse( Person firstPerson )
    {
        firstPerson.setLocation( null );
        Backendless.Data.of( Person.class ).save( firstPerson, new AsyncCallback<Person>()
        {
            @Override
            public void handleResponse( Person response )
            {
                // location has been deleted
            }

            @Override
            public void handleFault( BackendlessFault fault )
            {
                // an error has occurred
            }
        } );
    }

    @Override
    public void handleFault( BackendlessFault fault )
    {
        // an error has occurred
    }
} );
Person class:
import com.backendless.persistence.Point

class Person {
   var location: Point? = null
}
Code to delete a Point property from Person in the database:
Backendless.Data.of<Person>(Person::class.java).findFirst(object : AsyncCallback<Person> {
   override fun handleResponse(firstPerson: Person) {
       firstPerson.location = null
       Backendless.Data.of<Person>(Person::class.java).save(firstPerson, object : AsyncCallback<Person> {
           override fun handleResponse(response: Person) {
               // location has been deleted
           }

           override fun handleFault(fault: BackendlessFault) {
               // an error has occurred
           }
       })
   }

   override fun handleFault(fault: BackendlessFault) {
       // an error has occurred
   }
})

Backendless.Data.of( "Person" ).findFirst( new AsyncCallback<Map>()
{
    @Override
    public void handleResponse( Map firstPerson )
    {
        firstPerson.put( "location", null );
        Backendless.Data.of( "Person" ).save( firstPerson, new AsyncCallback<Map>()
        {
            @Override
            public void handleResponse( Map response )
            {
                // location has been deleted
            }

            @Override
            public void handleFault( BackendlessFault fault )
            {
                // an error has occurred
            }
        } );
    }

    @Override
    public void handleFault( BackendlessFault fault )
    {
        // an error has occurred
    }
} );
Backendless.Data.of("Person").findFirst(object : AsyncCallback<MutableMap<Any?, Any?>> {
   override fun handleResponse(firstPerson: MutableMap<Any?, Any?>) {
       firstPerson["location"] = null
       Backendless.Data.of("Person").save(firstPerson, object : AsyncCallback<MutableMap<Any?, Any?>> {
           override fun handleResponse(response: MutableMap<Any?, Any?>) {
               // location has been deleted
           }

           override fun handleFault(fault: BackendlessFault) {
               // an error has occurred
           }
       })
   }

   override fun handleFault(fault: BackendlessFault) {
       // 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'";
Map<String, Object> changes = new HashMap<>();
changes.put( "location", null );
Backendless.Data.of( "Person" ).update( whereClause, changes, new AsyncCallback<Integer>()
{
    @Override
    public void handleResponse( Integer objectsUpdated )
    {
        // objectsUpdated is how many objects were updated by the API call
    }

    @Override
    public void handleFault( BackendlessFault fault )
    {
        // an error has occurred
    }
} );
val whereClause = "email = 'bob@thebuilder.com'"
val changes = mutableMapOf<String, Any?>()
changes["location"] = null
Backendless.Data.of("Person").update(whereClause, changes, object : AsyncCallback {
   override fun handleResponse(objectsUpdated: Int?) {
       // objectsUpdated is how many objects were updated by the API call
   }

   override fun handleFault(fault: BackendlessFault) {
       // an error has occurred
   }
})