Advance AngularFirestore2 Query
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?
Answer
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)
Related Questions
- → Make a Laravel collection into angular array (octobercms)
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → Angularjs not working inside laravel form
- → Analysis of Flux implementations
- → how to write react component to construct HTML DOM
- → angular ng-repeat and images in a row
- → Conditional BG Color on AngularJS
- → Should I 'use strict' for every single javascript function I write?
- → getting the correct record in Angular with a json feed and passed data
- → "Undefined is not a function" at .toBe fucntion
- → angularjs data binding issue
- → Angular / JavaScript auto hydrate an instance
- → Convert generic text string in json object into valid url using Angular