0
votes

This is my database structure part 1database structure part 2

When you go into posts collection there are documents based on userId. And inside a document there is a new collection named userPosts. Inside userposts you can find postId and the details about the post.

I can get specific user post by using this code

postRef = Firestore.instance.collection('posts');

QuerySnapshot snapshot = await postRef
        .document(userId)
        .collection('userPosts')
        .getDocuments();

But I want to get all the user posts without naming a specific user. How could I achieve this?

1

1 Answers

1
votes

You can use a collection group query to query documents among all collections with same name.

QuerySnapshot snapshot = await Firestore.instance
        .collectionGroup('userPosts')
        .getDocuments();