【问题标题】:how to delete a complete collection including sub-collection in firebase firestore如何删除完整的集合,包括firebase firestore中的子集合
【发布时间】:2021-05-31 16:27:14
【问题描述】:

我正在制作一个应用程序,我必须在其中制作汽车发票,我用来存储发票的模式如下图所示

  containerInvoice: {
                    invoiceNo:123,  
                    total:$9000,
                    container:{
                               containerNo:911,
                               containerTotal:$201999
                               units:{
                                      id:199,
                                      chasis:a829nn, 
                                     }
                              }
                    }

如果我直接删除 containerInvoice's 文档,则删除成功,但子集合和子子集合未删除。

我删除整个集合包括其子集合的方法是通过文档的 id 访问这些文档并删除它,但这是一个漫长的过程。

有什么方法可以删除父集合,所有子集合都自动删除

【问题讨论】:

标签: google-cloud-firestore react-hooks


【解决方案1】:

正如@danh 指出的那样,根据文档,当您删除文档时,Cloud Firestore 不会自动删除其子集合中的文档。

如果您想删除一个文档及其子集合中的所有文档,您必须手动执行此操作 [1]。

要删除 Cloud Firestore 中的整个集合或子集合,请检索集合或子集合中的所有文档并将其删除 [2]。

[1] - https://firebase.google.com/docs/firestore/manage-data/delete-data#delete_documents

[2] - https://firebase.google.com/docs/firestore/manage-data/delete-data#collections

【讨论】:

    猜你喜欢
    • 2021-08-27
    • 2022-10-04
    • 1970-01-01
    • 2021-12-08
    • 2020-08-19
    • 1970-01-01
    • 2019-09-02
    相关资源
    最近更新 更多