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

316
Views
How to get data from all subcollection of docs of firebase in React JS?

This is how my firebase database looks like

This is how my firebase database looks like

How can I get all orders data from this database ?

This is how I have stored data :

db
    .collection('users')
    .doc(user?.email)
    .collection('orders')
    .doc(paymentIntent.id)
    .set({
        basket: basket,
        amount: paymentIntent.amount,
        created: paymentIntent.created
    })

setSucceeded(true);
setError(null);
setProcessing(false);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to fetch initial collection snapshot and then get all subcollections.

If you're querying for a specific doc you can get a direct query result straight away:

const id = 123 // 'replace with whatever user you're trying to query'
const userOrders = await firebase.collection('users').doc(id)
 .collection('orders').get()
 .then(doc => doc.exists ? doc.data() : null)

Otherwise you'll need to perform two consequentive fetches

const ordersSnapshot = await firebase.collection('users').get()
const allOrders = await Promise.all(ordersSnapshot.docs.map(async ({ id }) => (
  firebase.collection('users').doc(id).collection('orders').get()
    .then(doc => doc.exists ? doc.data() : null)
)))
about 4 years ago · Juan Pablo Isaza Report

0

Using Collection Group Queries might be the easiest way which fetches all documents from collections with same name which is passed in collectionGroup() method:

db.collectionGroup("orders").get().then((querySnapshot) => {
  console.log(querySnapshot.docs.map(d => ({id: d.id, ...d.data()})))
})

This will log an array of all orders.

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!