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

95
Visualizações
Fetch firebase nested subcollections for multiple documents with 'where'

I'm creating a simple web application and want to fetch 10 particular posts replies at a time by their postIds.

I'm using Firebase firestore, here is my database design posts/{postDocument}/replies/{replyDocument}.

Reply here is a document inside a collection replies which contains into a document post

My use case is that I want to fetch 10 posts at a time and so for each post also its subcollection (replies)

If I do a loop like for each postDocumentId await fetchReplies(postDocumentId) it will take too much time for one iteration (10 iterations overall)

I want to achieve something like this:

  let postIds = [ '123', '321', '221','123', '021', '621','423', '521', '291','251' ]
  let snapshot = await firestore()
          .collection('posts/replies')
          .where('postId', 'in', postIds)
          .get();

In the end I want to get data from firebase the most optimal way and get it in this type:

[{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]},
{post:{...},
replies:[{...},{...}]}]

Thank you in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can read documents from all replies collections with a collection group query.

But there's no way to limit that to the replies collections under a specific set of document IDs, unless those document IDs are also in the replies documents.

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