Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!