5
votes

I created an entity in the Google App Engine datastore.

How can I remove this entity?

4

4 Answers

4
votes

You haven't specified which API you're using.

In Python it's like so:

db.delete(modelId)

In Java it should be like (I haven't tested this):

PersistenceManager pm = PMF.get().getPersistenceManager();

MyModel entity = pm.getObjectById(MyModel.class, modelId);
pm.deletePersistent(entity);

pm.close();
3
votes

In python if you know the key it really simple:

db.delete(key)
0
votes

I am assuming that you have an endpoint:

Somethingendpoint endpoint = CloudEndpointUtils.updateBuilder(endpointBuilder).build();

And then:

endpoint.remove<ModelName>(long ID); 
0
votes

Additionally, you can also try something like the following (In Python pseudo-code):

class MyClass(ndb.Model):
    myString = ndb.StringProperty(indexed=false)

def deleteAllEntities():
    entities = MyClass.query()
    for entity in entities:
        entity.key.delete()

Admittedly there are better ways to do bulk deletion, but this is a way you can use if you are having trouble.

More info here: https://cloud.google.com/appengine/docs/python/datastore/entities#Python_Deleting_an_entity