Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

428
Visualizações
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 Respostas
Responde à pergunta

0

  1. userDocs is undefined inside addNew.
  2. userDocs is an object, not a single value.
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda