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

117
Visualizações
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 Respostas
Responde à pergunta

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