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

154
Views
Query a subcollection from a specific doc

my firestore databse looks like this:

groups ( collection ) => group of certain id ( doc ) => quizzes (subcollection)

All i want to do is to write a query in js that returns an array of all the quizzes from a group with a given id

The code i wrote looks like this:

  export const fetchQuizzesFirebase =  async function (idGroup) {
    if (!idGroup) return [];
    const quizzes = await firestore
      .collection(`groups`)
      .doc(idGroup)
      .collection(`quizzes`)
      .get();
  
    return quizzes.filter(doc => doc.exists).map(doc => ({ id: doc.id, ...doc.data() }));
  }

But it doesn't work and i can't seem to fix it. What am i missing?

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

0

Your query seems correct but you should use map on the .docs property instead of the QuerySnapshot. I'll also make sure if that group ID exists by console.log(idGroup) and also that .filter() is redundant. You've received a querySnapshot and all documents in that exists.

console.log(`${quizzes.size} quizzes found`) // Check quiz count
return quizzes.docs.map(doc => ({ id: doc.id, ...doc.data() }));
               ^^^^

Using a map only will do.

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!