I want to insert an object to the Firestore document as per the code mentioned below. but it's throwing the error
.update({
"comments": firebase.fieldValue.arrayUnion({
userId,
comment: data.comment,
createdAt: firebase.fieldValue.serverTimestamp(),
})
Error:
FirebaseError: Function FieldValue.arrayUnion() called with invalid data. FieldValue.serverTimestamp() can only be used with update() and set() (found in document...)
How can I add a timestamp to the pushed array object or is there any other way to achieve a similar result? what am I getting from the error above is I can't use the timestamp inside arrayUnion