Reputation: 1731
I wanted to delete an entire collection in firestore.
I used the firebase command - firebase firestore:delete product/
Error: Must pass recursive or shallow option when deleting a collection.
Again tried - firebase firestore:delete product/1
Error: Document has children, must specify -r or --shallow.
Please help me know, what does -r and -shallow means?
Which option should I preferably choose for bulk delete of entire collection using firebase command? I need to delete the entire docs inside the collection.
Upvotes: 2
Views: 1374
Reputation: 25134
To understand the arguments, you can use --help
:
$ firebase firestore:delete --help
Usage: firestore:delete [options] [path]
Delete data from Cloud Firestore.
Options:
-r, --recursive Recursive. Delete all documents and subcollections. Any action which would result in the deletion of child documents will fail if this argument is not passed. May not be passed along with --shallow.
--shallow Shallow. Delete only parent documents and ignore documents in subcollections. Any action which would orphan documents will fail if this argument is not passed. May not be passed along with -r.
--all-collections Delete all. Deletes the entire Firestore database, including all collections and documents. Any other flags or arguments will be ignored.
-y, --yes No confirmation. Otherwise, a confirmation prompt will appear.
-h, --help output usage information
The two options here are -r
(recursive) or --shallow
.
If you pass -r
when deleting a document, then it will also delete all subcollections of the document as well as all subcollections of subcollections, etc.
If you pass --shallow
it will only delete the document in question and will leave any subcollections intact.
Upvotes: 3
Reputation: 1731
tried both -
firebase firestore:delete -r <path>
deletes all the docs(deeply nested also) inside a collection
firebase firestore:delete -shallow <path>
deletes all docs (1 level) inside the collection, it just unlink the collection from children docs, path still exists to fetch deeply nested children.
Upvotes: 1