0

In Firestore, if I have as list of, say, 20 document IDs, what is the best way to fetch all those documents?

I'm thinking of, for example, using something like Angolia for search and getting a list of ids back from it.

Would I need to manually get or onSnaptshot each reference, or is there a more performant/simple way to fetch a list of documents just using their ID?

Thanks!

Nathan
  • 73,987
  • 14
  • 40
  • 69
  • It really does not matter much whether you get them each individually or use a series of 'in' queries to do batches. All the queries are pipelined over a single connection and you would be saturating that connection in either case, waiting for each document to be returned entirely. – Doug Stevenson Jun 29 '22 at 01:27

1 Answers1

0

A lot of the options depends on how your firestore is structured, and what framework you're using to encorporate firebase.

Generally speaking, querying a list can be done using the in query operator.

In the case of id querying, the array is id's, and you query by firebase.firestore.FieldPath.documentId()

import { query, where } from "firebase/firestore";

const q = query(firebase.firestore.FieldPath.documentId(), where('id', 'in', ['SOME_ID_1', 'SOME_ID_2']));


smcrowley
  • 451
  • 3
  • 10
  • But the in operator has a limit of 10 items, right? – Nathan Jun 29 '22 at 12:03
  • It does have a list limit of 10, but you can split your query list to get them in groups of 10, or use snapshots. Here's a link with those solutions https://stackoverflow.com/questions/59257753/firebase-firestore-query-an-array-of-more-than-10-elements – smcrowley Jun 30 '22 at 15:06