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

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

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 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