Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

405
Views
Get data from sub-collections in Firebase Firestore using nested query

I have following data structure in firestore:

  • flights [collection]
    • user1 [doc]
      • userFlights [sub collection]
        • flight 1
        • flight 2
        • flight 3
    • user2 [doc]
      • userFlights [sub collection]
        • flight 1
        • flight 2
        • flight 3

In order to read the data from all userFlights subcollections i use nested query as shown below.

My question: Would nested queries cause performance issues?

const userFlightRef = query(collection(db, "flights"));
const userUidDoc = await getDocs(userFlightRef);
userUidDoc.forEach(async userDoc => {
  const userFlightsQuery = query(collection(db, "flights/" + userDoc.id + "/userFlights"))
  const userFlights = await getDocs(userFlightsQuery);
  userFlights.forEach(flyer => {
     console.log(flyer.data());
  });
});

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to search all userFlights collections, you can use a collection group query.

You can get all documents from all userFlights collections with:

getDocs(collectionGroup(db, "userFlights"));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!