1

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).

Carlos Pisarello
  • 1,254
  • 5
  • 20
  • 39
  • 1
    Instead of saying "something like" and a query with missing parameters, can you edit your question to show: 1) a screenshot of the document you want to query? 2) the actual code that you're using/looking to use with all arguments filled in? – Frank van Puffelen Apr 05 '20 at 04:13
  • You can query using an object or a Map that contains both properties. – Alex Mamo Apr 05 '20 at 14:29

0 Answers0