user123456
user123456

Reputation: 181

add/update array in collection with firestore and react native

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

Answers (1)

Renaud Tarnec
Renaud Tarnec

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

Related Questions