How do I delete an entire ancestor tree via the API (Python protocol buffer) in Google Cloud Datastore?
For example, if I have entities stored in this structure: grandparent/parent/child, how can I delete the grandparent, and in so doing delete all the children and grandchildren of that "node"?
If I submit a delete request on the grandparent's key, the grandparent entity is deleted, but its children and grandchildren remain, and their path is still grandparent/parent/child, even though the grandparent entity was deleted.
Open "Datastore Admin" for your application and enable Admin. Then all of your entities will be listed with check boxes. You can simply select the unwanted entites and delete them.
Deleting unused indexes When you are sure that old indexes are no longer needed, you can delete them by using the datastore indexes cleanup command. This command deletes all indexes for the production Datastore mode instance that are not mentioned in the local version of index.
Unfortunately, there is no way to purge the previous existence of a Cloud Datastore database to try either Cloud Firestore in native or Datastore mode. You'll have to use a new project to try Cloud Firestore in either native or Datastore mode. @Eduardo Your answer should be considered the correct one.
Navigate to the objects, which may be located in a folder. Click the checkbox for each object you want to delete. You can also click the checkbox for folders, which will delete all objects contained in that folder. Click the Delete button.
Deleting a parent entity will not delete any of the child entities. However, you can use an ancestor query to find the keys of all of the child entities and delete them as part of a single transaction. The steps would be:
Here's a partial code snippet:
# Create a transactional RunQueryRequest.
req = datastore.RunQueryRequest()
req.read_options.transaction = txn # From previous BeginTransactionRequest.
query = req.query
# Add an ancestor filter.
key_filter = query.filter.property_filter
key_filter.property.name = '__key__'
key_filter.operator = datastore.PropertyFilter.HAS_ANCESTOR
path_element = key_filter.value.key_value.path_element.add()
path_element.kind = 'ParentKind'
path_element.name = 'parent-name'
# Make it a keys-only query.
query.projection.add().property.name = '__key__'
batch = self.datastore.run_query(req)
for entity_result in batch:
# Add entity_result.entity.key to CommitRequest...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With