0

I have this path to a subcollection in a Firebase Firestore: Team/TeamName/Meetings/First/Data. I wonder if there is any way how to get the docs in the data subcollection based on the values (fields) in the first doc (parent doc).

I tried this:

 db.collection("Team")
            .doc("TeamName")
            .collection('Meetings').where('0', '==', "some data")
            .where('3', '==', "doc data")
            .where('4', '==', "something in textfiel").collection("Data")

But this approach does not work.

radim.1
  • 99
  • 1
  • 3
  • 12

1 Answers1

1

Firestore queries can only consider fields of documents immediately in the collection or subcollection of the query. There are no "joins" that combine data between documents across multiple collections.

What you're trying to do requires at least two queries. First, a query to get the parent documents from "Team":

db
    .collection("Team")
    .where(/* your conditions on Teams documents here */)
    .get()

Then, for each matching parent document, you will need more queries for documents in each subcollection.

db
    .collection("Team")
    .doc(matchingDocId)
    .collection("Meetings")
    .where(/* Any filters on documents in Meetings */)
    .get()
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441