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

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

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 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