1
votes

I'm looking for an example to delete items from Google Cloud Datastore by:

  • Key
  • Kind
  • Filter
  • Ancestry

ps: I couldn't find them here: https://developers.google.com/datastore/docs/concepts/queries

1
there's no example as none is needed really. Fundamentally you get the model you want, then model.delete(). How you get that list of models is where the query (kind, filter etc) comes in, but once you have it just call delete on the model instance you want gone. You'll want to do a "keys only" query otherwise you'll retrieve the data for the models which is not needed if you are only going to delete them.Paul Collingwood
There is no DELETE FROM KIND [WHERE X = Y] equivalent? I need to delete them individually?Sjuul Janssen
AttributeError: 'Entity' object has no attribute 'delete' Are you sure you're not mistaking my question for an App-Engine question?Sjuul Janssen
oops, yes, sorry! Duh...Paul Collingwood

1 Answers

3
votes

Google Cloud Datastore only supports delete-by-key (and in general, does not support "update queries").

To delete a small number of entities, you can execute a (keys-only) RunQuery operation to fetch the keys and then a BlindWrite request to delete the entities.

Or, if the entities are in a single entity group, you can do the entire operation inside a transaction using BeginTransaction to create a new transaction, set the transaction handle in the query ReadOptions, and a Commit request to apply the mutation.

If you are deleting a large number of entities, you can use the above technique in a MapReduce.

If you are deleting all entities of a particular kind, you can use the App Engine Administration Console to delete entities in bulk.