2

I have an application with the following firestore data structure:

  • groups
    • groupId
      • members
        • memberId

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 ?

Jens Verrydt
  • 33
  • 1
  • 4

2 Answers2

2

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Would this also work when the documents & collections are secured with an author field limiting only owners to delete their data? – jonasxd360 Jun 29 '18 at 18:28
  • 1
    Guide to setting up a callable Cloud Function to recursively delete now in the docs: https://firebase.google.com/docs/firestore/solutions/delete-collections – Juan Lara Sep 25 '18 at 21:24
2

Using the firebase-cli:

firebase firestore:delete -r /<collection path>

firebase firestore:delete --all-collections
Birch
  • 211
  • 2
  • 8
  • can the firebase cli target a firestore database? I thought it can only access the firebase realtime database – Ari Nov 19 '19 at 03:16