0

I'm trying to delete a post and all its sub-collections. When using the code below, I'm only able to delete all the fields in the post, but NOT the sub-collections it has.

FirebaseFirestore.instance.collection('posts').doc(postId).get().then((doc) {
      if (doc.exists) {
        doc.reference.delete();
      }

What should I change to make it work? Thanks a lot!

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Alvaro-99
  • 21
  • 3
  • There is no client side operation for this. You would have to manually query for and individually delete each document. Or, do it on the backend as shown in the duplicate. – Doug Stevenson Jul 12 '21 at 17:31
  • @DougStevenson Thanks for the quick reply. How would you manually do it? How would "do it on the backend as shown in the duplicate"? – Alvaro-99 Jul 12 '21 at 18:09
  • The duplicate has lots of examples you can follow. That's why I marked it as a dup - it's the same question. – Doug Stevenson Jul 12 '21 at 18:32

0 Answers0