【问题标题】:Firestore : Document has children, must specify -r or --shallowFirestore:文档有孩子,必须指定 -r 或 --shallow
【发布时间】:2018-03-05 03:18:09
【问题描述】:

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

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

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

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

    要理解参数,可以使用--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,它将删除有问题的文档,并保留所有子集合。

    【讨论】:

      【解决方案2】:

      都试过了——

      firebase firestore:delete -r <path>

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

      firebase firestore:delete -shallow <path>

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

      【讨论】:

      • 另外,您可以通过以下方式获取使用信息:firebase firestore:delete --help
      猜你喜欢
      • 2018-09-26
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      相关资源
      最近更新 更多