I have two main collections:
groups
, which is keyed on auto-ids, and hasGroupID = (auto-id)
,Creator
andGroupname
fields.users
, which is keyed onuid
, and has a subcollectionusergroups
which contains allGroupIDs (auto-ids from the Groups collection)
that are assigned to the user.
Now I want to filter the groups
collection with the usergroups
collection.
The result should be that the user only sees the groups that are saved in his user profile.
My first attempt looks like this:
Stream<QuerySnapshot> userGroupIDs() async*{
String docId;
Stream<QuerySnapshot> snap = Firestore.instance.collection("users").document("uid").collection('usergroups').snapshots();
await for(var snapData in snap){
snapData.documents.forEach((docResult){
docId = docResult.documentID;
});
}
yield* Firestore.instance.collection('groups').where('GroupID', isEqualTo: docId).snapshots();
}
Then inside StreamBuilder
:
StreamBuilder<QuerySnapshot>(
stream: userGroupIDs(),