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

115
Views
Is there a way to return document ID by checking field values

I am creating a Firebase cloud function and would like to get the ID of a document from a collection by checking it's key values.

I have a collection with several documents. Each document has a unique company_number which is different from the document ID. I would like to get the document ID and store it in a constant.

  const company_id = admin.firestore()
  .collection('company_collection')
  .where('company_number', '==', 'company_number')

I know my code is wrong but dont know how to correct it. I am new to Firebase and any help will be appreciated.

Thanks,

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It seems the company_number is unique to each document so you can read ID of first document in the returned QuerySnapshot as shown below:

const companyDoc = await admin.firestore()
  .collection('company_collection')
  .where('company_number', '==', 'company_number')
  .get()

// Check if that 1 doc is returned
if (companyDoc.empty) return "Document Not Found"

const company_id = companyDoc.docs[0].id
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!