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

87
Views
Can I add A Firebase collection in a collection

I have a form that collects user information and favourite foods But when collecting favourite food I want the favourite Food collection to be a Child to the 'users' collection Likes:

const sendPosts = (e) => {

    e.preventDefault()
    db.collection("users").add({
    
    //here I add the user details
    name: "userName",
    lastName: "userLastName",
    
    //is it possible to also add a collection like this after "lastName"
    
    collection("favFood").add({
    favDrink: "userDrink",
    favDessert: "userDesert",
      })
    })
  }

is it possible to do it like that or is it impossible or there is a simple way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes it is possible, since the add() method returns the DocumentReference of the newly created document.

db.collection("users").add({
    name: "userName",
    lastName: "userLastName"
})
.then(userDocRef => {
    userDocRef.collection("favFood").add({
        favDrink: "userDrink",
        favDessert: "userDesert",
    });
});

userDocRef.collection("favFood") declares the CollectionReference of the favFood subcollection of the newly created user document. See the doc.

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!