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

301
Visualizações
Problem when add data in Subcollection Firebase v9
await addDoc(collection(db, 'users', idDoc, 'notes'), {
    title: noteTitle,
    body: 'comentario por defecto.',
    timestamp: serverTimestamp(),
});

Error

My Databases Structure

When I trying to add data in my sub collection 'notes'. Appear this mistake, I don't know what is happening because I using the same code reference in Firebase v9 Documentation.

Extra Note: idDoc returns me: YYwcNWMfznuwAB8eN0sU

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

you use await first see async function is nesscesssry

addDoc(collection(db, 'Institute', 'Private', 'College'), { name:"tunio" })

this is working for me

about 4 years ago · Juan Pablo Isaza Relatório

0

try this one for add subcollections in firebase v9

`function uploadData() {
    var id = 'id_' + Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36); //create id for uniqness

    setDoc(doc(db, "Institute", `college`, `city`, `${id}`), {
        Name: "CAted college"
    })}`

//if you not use id set primary as name then no need to use id only write "name" of sugeesttion that unique for data base instead of id

about 4 years ago · Juan Pablo Isaza Relatório

0

It seems you were in the right direction but I would recommend checking how to reference subcollections and then using that reference to write data into it.

It won't hurt to check your imports and dependencies as well.

import  { doc } from "firebase/firestore";  

const messageRef = doc(db,  "rooms",  "roomA",  "messages",  "message1");

This translated to your project would be:

const notesRef = doc(db, 'users', idDoc, 'notes'); 

Next, you need to check the Add a document section as well. The code you are using as a reference applied to your app would create a new note with an auto-generated id. In the reference, "cities" would correspond to your "notes" reference.

Finally, if you substitute this, it would look like this:

const noteRef = await addDoc(collection(db, notesRef), {
    title: noteTitle,
    body: 'comentario por defecto.',
    timestamp: serverTimestamp() // You also had an extra coma here
});
console.log("Note written with ID: ", noteRef.id);

The console log is optional

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