我想在firestore中删除整个集合。
我使用了firebase命令 - firebase firestore:delete product/
错误:删除集合时必须传递递归或浅选项。
再次尝试 - firebase firestore:delete product/1
错误:文档有子项,必须指定-r或--shallow。
请帮帮我,-r和-shallow是什么意思?
我应该选择哪个选项使用firebase命令批量删除整个集合?我需要删除集合中的整个文档。
要理解这些参数,可以使用--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
这里的两个选项是-r
(递归)或--shallow
。
如果在删除文档时传递-r
,则它还将删除文档的所有子集以及子集的所有子集等。
如果您通过--shallow
,它将只删除有问题的文档,并保留所有子集合。
试过两个 -
firebase firestore:delete -r <path>
删除集合中的所有文档(也深度嵌套)
firebase firestore:delete -shallow <path>
删除集合中的所有文档(1级),它只是将集合与子文档取消链接,路径仍然存在以获取深层嵌套的子级。