Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!