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

224
Vistas
how to add an object to a document in firebase

In my code, I get an object from an existing Firebase collection and then I want to add it to another document as an object, however I don't understand how to do it

  // Create a query against the collection.
const q = query(subjectRef, where("Subject", "==", subject), where("Board", "==", examBoard), where("Level", "==", level));
onSnapshot(q, (snapshot) => {
  snapshot.docs.forEach(doc => {
    //add a document to a subcollection in the collection users
    const auth = getAuth();
    //editted so onAuthState function is not called
    const uid = auth.currentUser.uid
    const docRef = doc(db, "users", uid);
    const colRef = collection(docRef, "subjects");
    addDoc(colRef, {
      //?????
    });
  })

the doc would be added to the collection subjects, this is what the doc looks like: collection subject > document and the structure of the users is (collection) users > (document) user > (collection) subjects > (document) what i want to add

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can get the user ID from auth.currentUser.uid property. Here's how you would achieve this:

const q = query(subjectRef, where("Subject", "==", subject), where("Board", "==", examBoard), where("Level", "==", level));
onSnapshot(q, (snapshot) => {
  snapshot.docs.forEach(doc => {
    //add a document to a subcollection in the collection users
    const auth = getAuth();
    var q = doc.data()
    const colRef = collection(db, "users", auth.currentUser.uid,"subjects");
    addDoc(colRef, {
      Board:q.Board
      Level:q.Level
      Subject:q.Subject
    });
    });
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