Deleting many child entities, some abandonded

14 views
Skip to first unread message

Jeremy D

unread,
Jul 23, 2021, 12:44:49 PM7/23/21
to Google Cloud Datastore
Is there a way to delete a _lot_ of child entities? Some of which have no parents (the parent was deleted without deleting the related child entity)

Currently, I'm thinking the way to do this (maybe the only way?) is to find the parent entities to be deleted, then query the related child entity, add them all into an array and call `delete_multi`. (we're using python-ndb)

In practice this means 1 query per parent entity. for 100k parents, that's 100k queries. Is there not a better way to do this? Are there datastore limitations around making a query like this?

Jim Morrison

unread,
Jul 23, 2021, 2:58:04 PM7/23/21
to Google Cloud Datastore
Hi Jeremy,

 Unfortunately, without knowing more about your schema it is hard to know what alternatives would be good for you.  One option you could look at is using a Dataflow job where you query for the kind and check if the parent entity exists for each entity.  If it does not, then issue the delete.

Jim

--
You received this message because you are subscribed to the Google Groups "Google Cloud Datastore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gcd-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gcd-discuss/63cd34d5-46b1-451d-b076-0b26e1067dcan%40googlegroups.com.


--
Jim

Jim Morrison

unread,
Jul 23, 2021, 3:30:04 PM7/23/21
to Google Cloud Datastore
There isn't a recursive delete method in NDB.

On Fri, 23 Jul 2021 at 12:21, Jeremy D <jdavi...@gmail.com> wrote:
The issue is less so about the abandoned entities and more about how to delete lots of entities and their child entities.

If there was a way within NDB for it to delete an entity and any children, that would be ideal but I don't think such a thing exists.



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