0

If I need 5 distinct documents from a Firestore collection. I don't need to query Firestore at all - I already have the document ID's. What is the best practice for fetching them?

I am currently using Promise.all to fetch them in parallel but it seems like a single call to Firestore would be even better in terms of network and compute overhead? However, I can't find a batch read method for the web SDK. Is Promise.all the best practice for fetching several documents at once?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
  • This was my problem too. My current best guess is that I create an "index" array in the document where this subcollection belongs. That will contain only the ids of the subcollection. And I am updating it when I add or remove document to/from the related subcollection. One can add or remove elements without updating the whole array, but the size limitation related to the document that that contains it is szill there. – ZorgoZ Sep 17 '18 at 19:11
  • @ZorgoZ after thinking about it, I posted the following answer to the duplicate question: ...avoid `Promise.all` unless you can't. Let the individual reads resolve independently so as to allow the client to resolve it's components ASAP. – Ronnie Royston Sep 17 '18 at 19:50
  • @RonRoyson Just keep in mind that each document touched (even if only its id is fetched) counts as a read operation! – ZorgoZ Sep 17 '18 at 19:52

0 Answers0