Query a subcollection from a specific doc

Solution for Query a subcollection from a specific doc
is Given Below:

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
    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?

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.