Closed sephina closed 4 years ago
I have tested my code against the latest library release (27) and I still get the blank date issue:
createDocument()
returns this:
fields: { formSubmitted: { mapValue: {} }, preferredName: { stringValue: 'H6' } ... }
@themcclure, I'm not following... where's the blank date? Can you provide more code in your example?
I have a test case called Test_Create_Document_Bare
and only passes the collection path to .createDocument(path)
, which returns an empty object with the random document name that Google assigned and appropriate Create and Update times.
There's another test case called Test_Create_Document_Data
which passes in data, and the output matches the input with the appropriate Create and Update times. This unit test also includes a 'timestamp data'
field to test data passed in as new Date()
(a Date object).
Both tests are passing.
We run into the same issue not saving Date() object in the document. { "dateStart" : new Date() }
Remains blank.
I noticed 2 things:
function wrapDate_ (date) { return {'timestampValue': date.toISOString()} }
The other and I think main issue I found is using the library as a library, the Date object that is passes is no longer evaluating as instanceof Date:
value instanceof Date //false
so Dates get sent as Mapvalues.
When logging the instance in the script calling FirestoreApp, it evaluates as 'true'. Checked it on V8 and non-V8, but not found out yet.
Bit of ugyl fix:
Verified that instanceof
fails for Date
objects outside of the library.
This line will be updated to include additional checks. Thanks for bringing this up!
Hey that a really good library, helped me a lot. Thanks!
I'm trying to create a document with a timestamp in it and I'm keep getting an empty map on Firestore.
firestore.createDocument(USER_EXPIRATION_COLLECTION, { userId: userId, classId: classId, timestamp: new Date()});
and the output:
{ name: 'projects/.../usersClassesExpiration/...', fields: { userId: 'userId', timestamp: {}, classId: 'classId' }, createTime: Tue May 26 2020 11:11:09 GMT+0300 (Israel Daylight Time), updateTime: Tue May 26 2020 11:11:09 GMT+0300 (Israel Daylight Time) }