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

122
Views
Firestore - how do i access .doc() random generated document ID?

trying to figure out this. Im using firestore and trying to store my random generated numbers/characters when im using .doc() while creating up documents instead of naming them.

Now my problem is i wanna make another collection inside that document. A subcollection that is. How do i go about this? Its super easy when i have a hardcoded variable because then i know directly what document to create it in. But how do i work around it with random generated chars/numbers?

Heres my entire thing

        company_id: CompanyID,
        })```

firestore.collection('books').doc().set({
        company_id: CompanyID,
        })        
        .then(() => {
            firestore.collection('books').doc().collection('messages').add({
            text: 'hej',
            createdAt: firebase.firestore.FieldValue.serverTimestamp(),
            myIdNumber,
            displayName,
            })
        })
        .catch((error: string) => {
            console.error("Error while creating: ", error);
        });```
about 4 years ago · Juan Pablo Isaza
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!