Function executes when a write is made in collection logs, it checks if doc exists in collection totals. If doc exists it is trying to update number object with number+1 at [0] of array.
Here is my code:
...//some code
var washingtonRef = admin.firestore().collection('totals').doc(entryDate_show);
washingtonRef.get().then((doc: any)=> {
if (doc.exists) {
console.log("doc found");
console.log("Document data:", doc.data());
washingtonRef.update({
[auth_ID]: admin.firestore.FieldValue.arrayUnion(
{ number: doc.data().number+1, // here it is trying to do +1
fullname: fullname,
authid: auth_ID },
)
});
...//some code
Problem: It is not working as expected
In array, it is adding new object [1] with number : NaN
Expected behaviour: number : 2 at [0]
Attaching pic of the console:
