I am trying to set a timestamp field on a nested element to the current time:
docRef.update({
arrayOfStuff: {
id: 123,
dateAdded: admin.firestore.FieldValue.serverTimestamp()
}
})
I get the error:
FieldValue.serverTimestamp() cannot be used inside of an array
Using Date.now() gets me an int value, not a timestamp.
Trying Firestore.Timestamp.fromDate() yields the error:
TypeError: date.getTime is not a function
at Function.fromDate (/srv/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/timestamp.js:108:42)
at firestoreDB.doc.get.then.site (/srv/index.js:32:45)
where line 32 of index.js is:
let now = admin.firestore.Timestamp.fromDate(Date.now());
Thoughts?
let now = admin.firestore.Timestamp.now()It yields a "timestamp" value in Firestore. I suspect the difference is that the timestamp I get comes from when the code runs, as opposed to serverTimestamp() that I believe is the time that the data is actually stored in Firestore (there can be a delay between the two times).