I'm saw that Firebase released collection group query, which is awesome. So in the example in the docs:
For example, this collection group query retrieves all museum landmarks across all cities
But how to get all cities that have museum landmarks? So I want to return city objects and not landmarks. How to solve this?
All I want to do is to get all the cities that have in theirlandmarks
subcollection, landmarks that are museum? Is this possbile with collection group query?
To start querying a collection, you need to provide the hooks with a CollectionReference or Query reference created directly from the firebase/firestore library. The reference can be a simple collection pointer or a fully constrained query using the querying functionality provided by the Firestore SDK.
Starting with… in queries! With the in query, you can query a specific field for multiple values (up to 10) in a single query. You do this by passing a list containing all the values you want to search for, and Cloud Firestore will match any document whose field equals one of those values.
In Cloud Firestore, your data is divided up into documents and collections. Documents often point to subcollections that contain other documents, like in this example, where each restaurant document contains a subcollection with all the reviews of that restaurant.
Basic Query A Collection Group Query allows you to join all the collections that share a similar name, in this case comments , and query across them uniformly. app.js. import * as firebase from 'firebase/app'; const db = firebase.
Queries return documents from the collections that you query. Since you're querying the landmarks
collections, the results returned will be landmark documents.
If you want the parent city documents, you will have to load those individually and separately.
Alternatively: consider if you can't add an array to your city documents that allows you to perform your query on that collection with array-contains
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With