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

210
Views
Need to write to collection in a collection in Firebase

I need to change my web app (JavaScript) I use to load products to Firebase Firestore to create a collection ('blue_bottle') in a collection ('promotions'). It use to write straight into a collection ('blue_bottle') which was sharp for time being. What do I have to add to make it write to a collection ('promotions') first, then to collection ('blue_bottle') I can't seem to find very much JavaScript and Firebase reference.

form.addEventListener('submit', (e) => {
e.preventDefault();
db.collection('blue_bottle').add({

Obviously this was the first thing I tried without success:

form.addEventListener('submit', (e) => {
e.preventDefault();
db.collection('promotions').db.collection('blue_bottle').add({

Now it first need to go to a collection ('promotions') please.

Thank you

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

0

The Firestore content model is that a document can only exist in a collection, and a subcollection can only exist in a document. There is no way to nest a collection directly under a collection.

To add something under a nested collection under a document, the syntax is:

db.collection('promotions').doc('the parent document').collection('blue_bottle').add({
  ...
})

Or shorter:

db.collection('promotions/the parent document/blue_bottle').add({
  ...
})
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!