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

264
Visualizações
How to dynamically get firestore subcollections and their contents?

I want to iterate through a list of subcollections inside my top-level collection and retrieve their data one by one, without first knowing the names of said subcollections. The subcollections canbe created by users, so I won't know their names/IDs ahead of time.

I've seen a couple of answers on here about getting subcollections, but they all seem to be with hardcoded collection names. Example A Example B

When I pull and console log out my toplevel herbalTeas collection currently, I just see a piece of dummy data. What I'd like to see is all my other subcollections (which are currently mint and chamomile, but could grow dynamically) in my console as well, so I can iterate and do things with their data.

See screenshot below of by firestore structure.

I'm console logging that data via this code:

const collectionRef = await getDocs(collection(db, "herbalTeas"));
collectionRef.forEach((doc) => {
  console.log(doc.data()); // logs out {test: "test}
});

Firestore

about 4 years ago · Juan Pablo Isaza
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