0

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..?

1 Answer 1

1

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');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.