I have the following Firestore setup in use:
Now I'd like to receive all documents where the current user (uid given) is in the users object/list. users is an object of references to thje users collection.
Ideally I would want to use this filter from Flutter with the cloud_firestore package, however for now I'm just interested if this is possible at all.
I found this post which explains, that is not currently possible how I imagined it. I altered my setup to this:
I can now use this query from Flutter to receive the chats for a given user
Firestore.instance
.collection('chats')
.where('users.' + _auth.currentUser.uid, isEqualTo: true)
.snapshots
.listen((data) {...});
I'm also using this rule to make sure that the user can only access the chats in which he is participating:
match /chats/{chatId} {
allow read: if resource.users[request.auth.uid];
// write rule yet to create
}
Yes. This is possible. However you will need to store you user references as a map of values and create a reference to query with in your client (based on the user ID). Take a look at the documentation: Working with Arrays, Lists and Sets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With