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

156
Visualizações
Saving the document id at the time of creating a document in Firebase v9 using React JS

Hello I want that when creating a new document, where it says "projectId" the id of the document that is automatically generated is passed to the "projectId" field, is this is possible?

enter image description here

This is my code:

addDoc(collection(db, "projects"), {
        name: project,
        uid: currentUser,
        projectId: 'here the proyectId that i dont know how to pass it'
        
        
      })

Im using Firebase v9 Modular, Firestore and React JS

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The following will do the trick:

import { collection, doc, setDoc } from "firebase/firestore"; 

// Add a new document with a generated id
const newDocRef = doc(collection(db, "projects"));

// Set the doc, using the id property of the DocumentReference
await setDoc(newDocRef, {
    name: project,
    uid: currentUser,
    projectId: newDocRef.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