query by object value inside array on firebase firestore

36 Views Asked by At

I'm working on a project where i have a collection (calles games), that contains documents (one for each game), that has a "players" array, each element inside that array is an object with two properties: id and role. i want to make a wuery to get all documents of the games collection where the players array contain an object with an id value that matches the user currently logged in, something like:

firestoreRef.collection('games').where('players', 'array-contains', /*an object which id property matches user.uid*/).get().then...;

i don't really know if that's possible with compund queries.

I have a workaround but that would require duplicated data, each player could have one of three roles: master, admin or adventurer. I'm thinking about leaving the players array as an array of strings with the players id, and have another array with the ids of the admins and another field with a string containing the id of the master (that could be just one per game).

0

There are 0 best solutions below