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

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

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