Reputation: 181
Im trying to add an object in the array "steps" from collection task, without delete the objects that already inside the array
queryDocumentSnapshot.ref.set({steps:[{title:newStep,completed:false}]});
alert('This task has been updated');
But when I use set, its deleted all the old fields.. Hoe can I update (add new element in the array) without delete..?
Upvotes: 0
Views: 1883
Reputation: 83191
As explained in the doc, you need to use arrayUnion
:
queryDocumentSnapshot.ref.update({
steps: firebase.firestore.FieldValue.arrayUnion({title:newStep,completed:false})
})
.then(() => {
alert('This task has been updated');
});
Upvotes: 1