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

225
Views
unable to append objects in firebase document
 var single_Catagory = [
        {
          name: title,
          price: price,
          scrachedPrice: scrachedPrice,
          color: colors,
          sizeList: sizes,
          stockStatusAvailablity: inStockAvailablity,
          productInStock: productInStock,
          rating: rating,
          productDescription: productDescription,
        },
      ];

      db.collection("catagory")
        .doc("catagories")
        .set({ electronics: single_Catagory })
        .then(() => {
          console.log("Document successfully written!");
        })
        .catch((error) => {
          console.error("Error writing document: ", error);
        });

this is my code for writing in my firebase firesore collection "catagroy" and it has one document "catagories",when I inserted one object I can't append other objects in firestore document. please I got stuck ..help me

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

0

How to add documents to firestore collection? And how to modify them?

// Add a new document in collection "cities"
db.collection("cities").doc("LA").set({
    name: "Los Angeles",
    state: "CA",
    country: "USA"
})
.then(() => {
    console.log("Document successfully written!");
})
.catch((error) => {
    console.error("Error writing document: ", error);
});

And if this document is not existing one its going to be created, but if its already there the data will be overwriten by the latest document.
Of course there is a option that can prevent that from happening.

var cityRef = db.collection('cities').doc('BJ');

var setWithMerge = cityRef.set({
    capital: true
}, { merge: true });

This explanation is very basic but usefull for further understanding of how firebase is working. All of it is from the firebase docs, they are very well made take a look at them.

https://firebase.google.com/docs/firestore/manage-data/add-data#web-version-8

about 4 years ago · Juan Pablo Isaza Report

0

In addition to Dobromir's answer on how to add another field to the document, here's how you can add another item to the electronics array in your existing document:

var second_Catagory = {
  name: "second name",
  price: price,
  scrachedPrice: scrachedPrice,
  color: colors,
  sizeList: sizes,
  stockStatusAvailablity: inStockAvailablity,
  productInStock: productInStock,
  rating: rating,
  productDescription: productDescription,
},

db.collection("catagory")
  .doc("catagories")
  .update({ electronics: firebase.firestore.FieldValue.arrayUnion(second_Catagory) })

Also see the Firebase documentation on adding items to an array.

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!