FirestoreGoogleAppsScript
FirestoreGoogleAppsScript copied to clipboard
Firestore number is sometimes returned as date 12/30/1899 0:00:00 or 10/26/1900 0:00:00
Minimal code to reproduce the problem
const firestore = FirestoreApp.getFirestore(email, key, projectId);
const allDocumentsRequested = firestore.query("bookings").Where("slotTime",">=",startingDate ).Where("slotTime","<=", endDate).OrderBy("slotTime").Execute().map(function(document){
return document.obj;
});
const first = allDocumentsRequested[0];
const columns = Object.keys(first);
const sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(displayedColumnNames);
allDocumentsRequested.forEach(function(document){
const row = columns.map(function(column){
return document[column];
});
sheet.appendRow(row);
});
Expected Behavior
To print out all Strings, Dates, Boolean and Numbers correctly.
Actual Results
All other non-number fields are working correctly however, on a few occasions the Numbers turn into 12/30/1899 0:00:00 or 10/26/1900 0:00:00, in the database i check the documents and they are numbers correctly example (300).
Library Version:
33
The workaround i found was to convert the returned value to a string, in the code above i checked if it's a number then i return document[column].toString(); I will keep this open however as i believe it's still a bug.
Is the data type is stored in Firestore correctly? Since Firestore stores each field attibuted to a specific data type, this library checks that metadata and converts from string to that data type.
Closing due to inactivity.
I seemed to miss the follow up apologies. Data types were stored correctly. A note was just that most numbers showed correctly on a few occasions however this issue would arise.
@yassinsameh can you provide some example data?
I left that project a year ago but an example at the top of my head. Document{ startDate:Timestamp object Price: 300.0 (Number) }
The price type and amount was fixed for all documents and upon inspection for the exporting issue the documents themselves were correct as the others with the same datatype and amount.
Sorry, the startDate
property doesn't provide sufficient information to followup. If someone else comes across this and has the same issue, please fill us in.