I have a field called jobsPosted as seen in the picture, so I want to add another job, I have dishwasher and waiter already. But I get an error with this query
db.collection("companies").doc("Tiradito").field("jobsPosted").set(postJobObject).then(function() {
console.log("Document successfully written!");
});
That's my postJobbject
var postJobObject = {
"position": this.state.selected,
"timeSchedule": this.state.timeSchedule,
"compensation" : this.state.compensation,
"experience" : this.state.experience,
"description" : this.state.description
}
pass the option to merge the new data with any existing document to avoid overwriting entire documents
var cityRef = db.collection('cities').doc('BJ');
var setWithMerge = cityRef.set({
capital: true
}, { merge: true });
source: https://firebase.google.com/docs/firestore/manage-data/add-data
Try
jobsPosted = {}
var postJobObject = {
"position": this.state.selected,
"timeSchedule": this.state.timeSchedule,
"compensation" : this.state.compensation,
"experience" : this.state.experience,
"description" : this.state.description
}
jobsPosted['newJob'] = postJobObject;
Then use update
db.collection("companies").doc("Tiradito").update(jobsPosted).then(function() {
console.log("Document successfully written!");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With