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

300
Views
How to get data from collection within collection in Firebase?

data structure

I am making a quiz application with React. There is a collection of questions in my category collection. I can access categories. How can I access this collection of questions? What should I add to my code?

const fetchData = async () => {
  const catRef = collection(db, "categories");

  const querySnapshot = await getDocs(catRef);
  querySnapshot.forEach((doc) => {
    console.log(doc.id, " => ", doc.data());
    //const questionRef = collection(db, `categories/${doc.id}/questions`);
     
  });
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The collection(db, 'categories/${categoryId}/questions'); approach is correct if you are trying to get questions of a specific category.

If you are trying to fetch questions from all categories then you can use a collectionGroup() query instead:

import { collectionGroup, query, where, getDocs } from "firebase/firestore";  

const questions = query(collectionGroup(db, 'questions'));
const querySnapshot = await getDocs(museums);
querySnapshot.forEach((doc) => {
    console.log(doc.id, ' => ', doc.data());
});
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!