开发者

How to delete entity from google App engine Datastore?

开发者 https://www.devze.com 2022-12-22 18:39 出处:网络
I created an entity in the Google App Engine datastore. Ho开发者_如何学Pythonw can I remove this entity?You haven\'t specified which API you\'re using.

I created an entity in the Google App Engine datastore.

Ho开发者_如何学Pythonw can I remove this entity?


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();


In python if you know the key it really simple:

db.delete(key)


I am assuming that you have an endpoint:

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

And then:

endpoint.remove<ModelName>(long ID); 


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

0

精彩评论

暂无评论...
验证码 换一张
取 消