Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore collection group query solution?

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?

like image 454
Hans Spigel Avatar asked May 08 '19 16:05

Hans Spigel


People also ask

How do I query a collection in firestore?

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.

How do I query multiple values in firestore?

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.

What is Collection group firestore?

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.

What is Collectiongroup in firebase?

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.


1 Answers

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.

like image 148
Frank van Puffelen Avatar answered Oct 19 '22 20:10

Frank van Puffelen