I have list of firestore documents ids stored in players
. Now I want to get all the documents with those ids.
I can use query
and in
operator, but this is limited to 10 separate values and I expect cases with more than 10. stackoverflow
const colRef = collection(db, "Products");
const q = query(colRef, where(documentId(), 'in', players));
getDocs(q).then((snap) => {
console.log(snap.docs.map(d => ({ id: d.id, ...d.data() }))
})
I stumbled upon this question where they are using getAll
, but this function is not available in firestore 9 AFAIK.
async getUsers({userIds}) {
const refs = userIds.map(id => this.firestore.doc(`users/${id}`))
const users = await this.firestore.getAll(...refs)
console.log(users.map(doc => doc.data()))
}
I could create a list of doc reference and using Promise.all
get the data, but this will run the request in parallel, which comes with additional cost as firestore gets billed per request and not per data volume as it is in realtime database.