Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda