Firestore:Document有子节点,必须指定-r或--shallow

时间:2018-03-05 03:18:09

标签: firebase google-cloud-firestore firebase-cli

我想在firestore中删除整个集合。

我使用了firebase命令 - firebase firestore:delete product/

  

错误:删除集合时必须传递递归或浅层选项。

再次尝试 - firebase firestore:delete product/1

  

错误:文档有子项,必须指定-r或--shallow。

请帮助我知道, -r -shallow 是什么意思?

我最好选择使用firebase命令批量删除整个集合的哪个选项?我需要删除集合中的整个文档。

2 个答案:

答案 0 :(得分:2)

要理解这些参数,您可以使用--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,则会删除相关文档,并保留所有子集合。

答案 1 :(得分:1)

尝试了两个 -

firebase firestore:delete -r <path>

  

删除集合中的所有文档(也深深嵌套)

firebase firestore:delete -shallow <path>

  

删除集合中的所有文档(1级),它只是将集合与子文档取消链接,路径仍然存在以获取深层嵌套的子项。