grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

Apps script FirestoreApp when query 'collection1' where 'timestampField' == my_variable_Timestamp #150

Open ab2d3e8 opened 1 year ago

ab2d3e8 commented 1 year ago

Minimal code to reproduce the problem

const firestore = FirestoreApp.getFirestore(email, key, projectId);
var my_variable_Timestamp = Utilities.formatDate(new Date(), 'GMT -1', 'yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'')
const docsFS = firestore.query("collection1").Where("timestampField", "==",  my_variable_Timestamp  ).Execute();

Expected Behavior

There are no results.

Actual Results

I did not find a way to make the query, try converting the date to a number, for example

var my_variable_Timestamp = Number(new Date().getTime()).toFixed(0);

But without any result. I expect the library FirestoreApp, It does not contain a property Timestamp like

var my_variable_Timestamp =  firestore.Timestamp.fromDate( new Date() )

Is there a solution to this problem

Library Version:

last Version;

michaelconan commented 1 year ago

It seems unlikely that you would have any documents with a timestamp matching the exact moment when you initialised my_variable_timestamp. In any case, I like you, expected to have to format my own timestamp (I used new Date().toISOString()), however, the query worked property when I passed a Date object to the .Where() method directly.