Jens Verrydt
Jens Verrydt

Reputation: 33

Delete firestore collection

I have an application with the following firestore data structure:

Now, when I want to delete a group, all it's members must be deleted accordingly. When I do this with a batched delete, the possibility exists that, when the client is offline, in the meanwhile new members are added so not everything will be deleted properly. How can I achieve this so everything about the group is properly removed ?

Upvotes: 2

Views: 3261

Answers (2)

Birch
Birch

Reputation: 217

Using the firebase-cli:

firebase firestore:delete -r /<collection path>

firebase firestore:delete --all-collections

Upvotes: 2

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

I recommend implementing this in Cloud Functions. You can either trigger that directly with a HTTP trigger, or through Cloud Firestore itself.

The latter has the advantage that the "delete" command can be sent/queued by a client while it is not connected, and will then be synchronized and executed correctly when it is next online.

Upvotes: 3

Related Questions