[英]flutter Bring nested collection from firestore
我正在开发 flutter 应用程序,我创建了名为“publicPost”的集合,其中包含文档,然后我有另一个嵌套集合及其文档,如图所示。
问题是当我试图从“publicPost”中检索并显示所有数据时,我做不到。 我需要指定一个文档,它只会带来一个文档的数据。 我怎样才能从主要收藏中取出所有文件。
这是我保存数据的代码
sendData() async {
final _documentReference = FirebaseFirestore.instance
.collection("publicPosts")
.doc(FirebaseAuth.instance.currentUser!.uid);
final _collectionReference = _documentReference.collection("postlist");
Map<String, dynamic> userInfoMap = {
"address": _addressController.text,
"bloodType": neVal,
"place": _placeController.text,
"post": _postController.text,
"date": FieldValue.serverTimestamp(),
"username": FirebaseAuth.instance.currentUser!.email,
"name": '$firstNmae $lastName',
};
await _collectionReference.add(userInfoMap);
if (mounted) {
Navigator.pop(context);
}
}
这就是我如何尝试使用此代码进行检索但我没有工作
final Stream<QuerySnapshot> _usersStream = FirebaseFirestore.instance
.collection('publicPosts')
.doc()
.collection('postlist')
.snapshots();
谁能帮忙解决这个问题?
要从所有postlist
collections 加载文档,您可以使用集合组查询。
FirebaseFirestore.instance
.collectionGroup('postlist')
.snapshots();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.