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

260
Visualizações
How to use 'Where' to read data from Firestore document in Google Cloud Functions?

I am trying to use the where clause to find a document in my Firestore database from my google cloud function, this is my code below when I try to just get a document with an ID, it works but when I try to use the where clause it doesn't, how can I fix this? Am I doing anything wrong

return await firestore.collection(COLLECTION_NAME).where('APIKEY', '==', '<APIKEY_VALUE>').get().then(doc => {            
  if (!(doc && doc.exists)) {
    return res.status(404).send({
      error: 'Unable to find the document'
    });
  }
  const data = doc.data();
  console.log(data);
  if (!data) {
    return res.status(404).send({
      error: 'Found document is empty'
    });
  }
  return res.status(200).send(data);
}).catch(err => {
  console.error(err);
  return res.status(404).send({
    error: 'Unable to retrieve the document',
    err
  });
});

Here is a screenshot of my Firestore database and the document I want to collect:

enter image description here

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

0

You are supposed to replace 'COLLECTION_NAME' with the name of the collection you want to find.

Replace firestore.collection(COLLECTION_NAME) with firestore.collection('accounts')

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