user123456
user123456

Reputation: 181

delete a collection and all the including data (collections and fields)

Im trying to delete a document X in collection Users but in this collection, there is another collection tasks is the collection Users. How can I delete all the data in the document X (includes collection tasks)

firebase.firestore().collection("Users").doc(X).delete();

Upvotes: 0

Views: 28

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

There is no single operation in the API to delete an entire collection. Instead a collection comes into existence once a first document is added to it, and a collection disappears once the final document is deleted from it.

This means that you'll need to delete each document in the collection individually, preferably using batch delete operations. Once you've deleted the last document from the subcollection, the collection itself is also gone.

Upvotes: 2

Related Questions