skip to Main Content

Can anyone tell me if it is possible to search multiple collections at once in Firebase?
What I need to do is search the data in both the 2009 and 2010 collections in bio_data (more collections will need to be added in the future) and extract the document from one of them.

Or it doesn’t matter if there is a way to get a name list of the collections inside a document

enter image description here

2

Answers


  1. Firestore does not have the concept of server-side joins or projections across collections. Each query or document read can only take data from a single collection, or from all collections that have the same name with collection group queries.
    If you need to load data from two collections, you’ll need at least two reads.

    For a better understanding I highly recommend watching the Get to know Cloud Firestore playlist.

    Login or Signup to reply.
  2. Michel’s answer is correct.

    In addition, I would suggest a change to your data model: Instead of having one sub-collection per year, you could have one unique sub-collection and add a year field to the docs in this unique collection.

    This way it would be easy to query by year: For one year, for several years with the in operator (up to 10 equality (==) clauses) or for all the years.


    And with a Collection Group query you could even query all the data for all the students.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search