Is it possible to query nested documents in Firestore without providing an argument to the .get()
method?
I would like to get all posts created by all users by looping through all the user ids and getting all the userPosts.
Below is the code I used.
Thank you very much.
getAllPosts() {
final CollectionReference postsRef = FirebaseFirestore.instance
.collection("posts");
var allPosts = postsRef.get().then((value) =>
value.docs.forEach((snapshot) {
var userPostsRef = postsRef.doc(snapshot.id);
var subCollection = userPostsRef.collection("userPosts").get();
print("subCollection $subCollection");
})
);
print("allPosts $allPosts");
}
print("subCollection $subCollection");
doesn't show anything on the console.
print("allPosts $allPosts");
shows Instance of 'Future' on the console.
Firestore structure:
posts -> userId -> userPosts -> postId -> {The actual post document}