Ad

Firestore - Query Via Timestamp Doesn´t Return Results

I wanna use the Timestamp as a Condition in my Query and end up with the following inside of my Cloud Function:

var dateRange = addMinutes(new Date(), 195); // 120 = timezone diff
dateRange = getTime(dateRange);

console.log(dateRange); // --> 1562933996501

const test = await fs.collection('tournaments').doc('B37tIBzDQDFXndv24KHs').get()

console.log(test.data().start); --> Timestamp { _seconds: 1562923800, _nanoseconds: 0 },

const queryRef = fs.collection('tournaments').where('status', '==', '0').where('start', '<=', dateRange);

But for some reason the querySnapshot´s size is 0, while the console.logs say that the variable dateRange = 1562933996501 and the test timestamp I query is 1562923800, so it should be in the area or not?

I use the timestamp field in Firestore for my timestamp. And yes the status of the document is 0.

EDIT trying this out:

console.log(test.data().status == 0) // = true
console.log(test.data().start.seconds < dateRange); // = true
Ad

Answer

It looks like you're trying to query a timestamp type field with an integer. That won't work. You can only query timestamps type fields with Timestamp type objects (as you output shows that you've gotten from the first query). Or, in JavaScript, you can pass a Date object, which will get converted to a Timestamp automatically.

Ad
source: stackoverflow.com
Ad