Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

600
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!