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

609
Vistas
Firebase v9 Firestore create document by id in React JS

How can i access to the document id?

I tried using doc().id but it doesnt work, how i can do it?

await addDoc(collection(db, 'users', currentUser.uid, 'proyects', doc().id, 'tasks'), {
            name: tarea,
            userUid: currentUser.uid,

        })

This is a capture of firestore, and i want to get the doc id of every document inside the proyects collection. And then create a collection named tasks inside of every of those documents.

This is a capture of firestore, and i want to get the doc id of every document inside the proyects collection. And then create a collection named tasks inside of every of those documents.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If the intention is to automatically create a new document ID using doc().id you would use:

const userProjectsColRef = collection(db, 'users', currentUser.uid, 'projects');
const newProjectDocRef = doc(userProjectsColRef);
addDoc(collection(newProjectDocRef, 'tasks'), {
  /* ... data ... */
});

This is because then first argument must be present and it must be either an instance of Firestore, CollectionReference, or DocumentReference. In order to use the automatically generated ID, you must pass in a CollectionReference.

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