Alexis
Alexis

Reputation: 1152

How to delete an entity by property in gae datastore

Key newwordKey = KeyFactory.createKey(NEWWORD_KEY_KIND, NEWWORD_KEY);
Entity newWord = new Entity(NEWWORD_ENTITY_KIND, newwordKey);
newWord.setProperty(USER_COL_USERNAME, userName);
newWord.setProperty(NEWWORD_COL, word);
datastore.put(newWord);

I mean I want to delete all "newword" Entity by its property "username" Ex, delete all words upload by user "Alexis" Any idea ? Thx

Upvotes: 0

Views: 128

Answers (1)

Pablo Chvx
Pablo Chvx

Reputation: 1931

Use the Delete Entities by Query function:

Query q = pm.newQuery(NEWWORD_KIND.class);
q.setFilter("USER_COL_USERNAME == USR");
q.declareParameters("String USR");
q.deletePersistentAll("Alexis");

More info here

Hope this helps.

Upvotes: 1

Related Questions