Spatial Data Delete API¶
There are two way to delete a spatial value from an object in the database:
- Using Backendless Console
- 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:
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:
- Retrieve from the database the data object which contains the spatial property to be deleted.
- Set the property value to
null
. - 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 }));
using BackendlessAPI; public class Person { public Point Location {get;set;} }
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 }));