How to delete all entities of a certain kind

2,010 views
Skip to first unread message

Marcel Overdijk

unread,
Oct 23, 2013, 4:33:56 PM10/23/13
to objectify...@googlegroups.com
What is the best way in Objectify to delete all entities of a certain kind?

Something like ofy().delete().type(Car.class).all();



/M

Grant Slender

unread,
Oct 23, 2013, 9:14:06 PM10/23/13
to objectify...@googlegroups.com
There is probably a better way, but this works well for me...

List<Key<Car>> keys = ofy().load().type(Car.class).keys().list();
ofy().delete().keys(keys).now();

Jeff Schnitzer

unread,
Oct 24, 2013, 1:16:35 AM10/24/13
to objectify...@googlegroups.com
That's pretty much how to do it. Be careful of the eventual consistency.

If you have really large numbers of entities (more than a few thousand) you will want to take some sort of map/reduce strategy. Of just use the admin console (which uses map/reduce).

Jeff


--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Brian White

unread,
Feb 8, 2023, 9:39:00 PM2/8/23
to objectify-appengine
10 years later...  This worked really well for me.  (Note that it's in Kotlin.)

val keys = ObjectifyService.ofy().load().kind<Any>(what).keys().list()
ObjectifyService.ofy().delete().keys(keys).now()

what is the saved entity "kind" (string) so it'll work even if the class that originally created the datastore no longer exists.

-- Brian
Reply all
Reply to author
Forward
0 new messages