Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda