YK07
YK07

Reputation: 9

Get all documents from Firestore Database

I'm currently making a Flutter app for practice, similar to a Twitter clone app. However, I have a problem when I try to get all documents from Firestore Database. I use UID as document id and want to see all user's posts. 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.........].

image

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.enter image description here

Upvotes: 0

Views: 132

Answers (1)

pradyot1996
pradyot1996

Reputation: 1074

If you need all the posts from posts's collection you only need

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

If you append .doc(uid).collection('talk') then this will fetch all the documents inside {uid}/talk.

Upvotes: 3

Related Questions