简体   繁体   English

从 Firestore 数据库中获取所有文档

[英]Get all documents from Firestore Database

I'm currently making a Flutter app for practice, similar to a Twitter clone app.我目前正在制作一个 Flutter 应用程序进行练习,类似于 Twitter 克隆应用程序。 However, I have a problem when I try to get all documents from Firestore Database.但是,当我尝试从 Firestore 数据库获取所有文档时遇到问题。 I use UID as document id and want to see all user's posts.我使用 UID 作为文档 ID 并希望查看所有用户的帖子。 But only the posts of the currently logged in user are displayed.但只显示当前登录用户的帖子。

In this case, how can I get all the documents?在这种情况下,我怎样才能得到所有的文件呢?

I want to display posts by user [B1vq9.........] and posts by [QVf5.........].我想显示用户 [B1vq9......] 的帖子和 [QVf5.........] 的帖子。

图片

I tried:我试过了:

final FirebaseAuth auth = FirebaseAuth.instance;
final User? user = auth.currentUser;
final uid = user!.uid;

FirebaseFirestore.collection('post').doc(uid).collection('talk').snapshots();

However, this code can only display posts from the currently logged in user.但是,此代码只能显示当前登录用户的帖子。

collection('talk') is a subcollection. collection('talk')是一个子集合。 enter image description here在此处输入图像描述

If you need all the posts from posts 's collection you only need如果您需要posts集合中的所有帖子,您只需要

FirebaseFirestore.collection('post').snapshots()

If you append .doc(uid).collection('talk') then this will fetch all the documents inside {uid}/talk .如果您 append .doc(uid).collection('talk')那么这将获取{uid}/talk中的所有文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM