[英]Not able to get a list of documents from Firebase Subcollection Flutter
I am creating an application where I need to have 3 heirarchy for email folders and notes like this:我正在创建一个应用程序,我需要为 email 文件夹和注释提供 3 个层次结构,如下所示:
Now I'm not able to get the list of documents under the folder collection.
现在我无法获取文件夹集合下的文档列表。
I have tried this till now:到目前为止,我已经尝试过了:
var collection = FirebaseFirestore.instance
.collection('user')
.doc(widget.email)
.collection('folder2');
await collection.get().then((snap) {
data = snap.size;
print(data);
});
But this is just giving me 0 in the console, but showing all the entries for the notes collection so what should I do?但这只是在控制台中给我 0,但显示了笔记集合的所有条目,所以我该怎么办?
try using the length of the documents retrieved in the result.尝试使用结果中检索到的文档的长度。
var collection = FirebaseFirestore.instance
.collection('user')
.doc(widget.email)
.collection('folder2');
await collection.get().then((snap) {
data = snap.docs.length;
print(data);
});
So I did get all the documents in the folder level by simply adding a few fields in that Collection like name, description etc. Though I still don't see a way to get all the documents containing subcollections without adding any fields.所以我确实通过简单地在该集合中添加一些字段(如名称、描述等)来获取文件夹级别的所有文档。尽管我仍然没有看到一种方法来获取包含子集合的所有文档而不添加任何字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.