0

Let say I have boards collections. Many users can participate in any board. So when every user participates I store user doc inside another collections 'participants'.

Now I want to show all the boards in which a particular user participate.

How to do that using angularfirestore?

enter image description here

enter image description here

SKG
  • 510
  • 4
  • 20

1 Answers1

1

What you're trying to do is known as a collection group query, which is currently not possible on Cloud Firestore. See Firestore query subcollections

So with your current model you can efficiently look up the users of a board, but you cannot efficiently look up the boards for a user. To allow the latter, consider adding a collection of boards for each user in a structure like /users/$uid/boards/$boardid.

Alternatively you can add an array field users to the board document and use an array-contains to perform the query:

db.collection('boards').where('users', 'array-contains', uid)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807