Get A Subscollection Of A Collection With A Where Query
How do I get a subcollection of a collection with a where query? This is what I've done so far:
getTasksByUserId(userId) {
this.logger.debug(`Getting tasks by user id ${userId}`);
if (userId) {
return this.afs.collection('tasks', ref => ref.where('createdBy', '==', userId)).valueChanges();
}
}
My collection looks like this:
I'd like to also get the contents of features
and tags
in one query.
Answer
Firestore read operations (including queries) return documents from a single collection only. If you need to return results from multiple collections, you'll to perform at least one read operation for the documents from each of those collections.
Consider if you really need the features and tags to be in subcollections, or whether they could also be (nested) fields in the document in the top-level tasks
collection. If you do need them to be in the subcollections (for example for querying them), consider duplicating the data both in the task document, and in the subcollections.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM