To update an array of objects with JavaScript Firestore, we call the set
method.
For instance, we write
firebase
.firestore()
.collection("proprietary")
.doc(docID)
.set(
{ sharedWith: [{ who: "abc@test.com", when: new Date() }] },
{ merge: true }
);
to get the proprietary
collection with collection
.
We get the document with docID
with doc
.
And we call set
to set the sharedWith
property to an array with the object we want to add.
We set merge
to true
to append the item to the existing sharedWith
property array in the document.