gpt4 book ai didi

android - Flutter Firebase删除子集合不起作用

转载 作者:行者123 更新时间:2023-12-03 04:47:02 25 4
gpt4 key购买 nike

在我的Firebase结构中,我有一个集合以及其中的一些子集合。我想在删除集合时也删除子集合。我正在尝试执行Firebase文档中的操作:“要删除Cloud Firestore中的整个集合或子集合,请检索集合或子集合中的所有文档并将其删除”。但是没有用。我删除了集合,并且子集合仍然保存。我的代码:

    void deleteNestedSubcollections(String id) {

Future<QuerySnapshot> books = libraryCollection.document(id).collection("Books").getDocuments();
books.then((value) => value.documents.remove(value));

Future<QuerySnapshot> catalogues = libraryCollection.document(id).collection("Catalogues").getDocuments();
catalogues.then((value) => value.documents.remove(value));
}

编辑1

enter image description here

最佳答案

要删除文档,您需要使用delete方法:


void deleteNestedSubcollections(String id) {
Future<QuerySnapshot> books =
libraryCollection.document(id).collection("Books").getDocuments();
books.then((value) {
value.documents.forEach((element) {
libraryCollection
.document(id)
.collection("Books")
.document(element.documentID)
.delete()
.then((value) => print("success"));
});
});
}

关于android - Flutter Firebase删除子集合不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62104658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com