Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

313
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda