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

418
Views
How do i get a FireStore document ID from an object?

I am trying to reference a auto generated firestore document ID so that I can create a subcollection in it.

The problem is while I am able to find that document ID, I can't seem to be able to save it to a variable where its usable.

Here I'm getting a specific document for the current user. of which userDocs has that documents ID in it. (getCollection is a composable that im calling)

const { documents: userDocs } = getCollection("userData", [
      "userId",
      "==",
      user.value.uid,
    ]);

Whenever I do console.log(userDocs), I get this object that has all the document info including the document id.

screenshot

However, when I try and drill down into the object to get the ID like with userDocs.value or userDocs.id, etc it just returns undefined.

If I run a v-for in the html like this:

<div v-for="docs in userDocs" :key="docs.id">
   <h1>{{ docs.id }}</h1>
</div>

It spits out the document id on a webpage no problem.

I'm trying to inject that document ID here so I can add a subcollection in firebase to this specific users document.

const addNew = async (plant) => {
      const userPlant = {
        plant: plant,
        planted: tempPlanted,
      };
      const res = await projectFirestore
        .collection("userData")
        .doc(userDocs)  <--------HERE
        .collection("plants")
        .add(userPlant);
    };

any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. userDocs is undefined inside addNew.
  2. userDocs is an object, not a single value.
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!