Rasm Mdv
Rasm Mdv

Reputation: 67

How to get all firestore documents with specific id in all snapshots?

This is my Flutter code for retrieve data snapshots . This return me 0 data :

final posts = FirebaseFirestore.instance.collection('posts');

return: StreamBuilder<QuerySnapshot>(
   stream: posts.doc().collection('userPosts').where('work', isEqualto: 'something').snapshot,
   builder.......
);





My Firestore structure:

enter image description here

Upvotes: 0

Views: 124

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83058

If I correctly understand your question, you should use a Collection group query and pass the following Stream to the StreamBuilder:

stream: Firestore.instance.collectionGroup('userPosts').where('work', isEqualto: 'something').snapshots();

The userPosts collection group consists of all (sub)collections with the ID userPost. Note that you must create an index that supports your collection group query.

Upvotes: 1

Related Questions