Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

261
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda