2👍
✅
You’re almost there. You can’t update the data of DocumentSnapshot
though, since that is the in-memory representation of the document data. Instead you need to get the DocumentReference
and call update
on that.
doc.ref.update({
postedProjects: firebase.firestore.FieldValue.arrayUnion("new project")
})
2👍
You need a DocumentReference in order to update() a document. Nothing else will work.
In your code, doc
is a QueryDocumentSnapshot
type object. If you want the DocumentReference object that refers to the document from that snapshot, use its ref property.
doc.ref.update({
postedProjects: firebase.firestore.FieldValue.arrayUnion("new project")
})
Source:stackexchange.com