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

146
Visualizações
get multiple docs from firestore by id in single transaction

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.

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

0

they are using getAll, but this function is not available in firestore 9 AFAIK.

Yes, the getAll() is a part of server side NodeJS SDK and not Firebase client SDK.

which comes with additional cost as firestore gets billed per request

Firestore reads are charged on number of documents fetched irrespective of how many queries you run i.e. 5 queries fetching 10 documents each will cost same amount of reads as a single query of 50 documents. At most you'll be charged for SSL overhead depending on the connection.

So one way is to execute multiple queries that'll fetch up to 10 documents each with in operator along with Promise.all() to run them in parallel.

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