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

96
Views
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 answers
Answer question

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 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!