Within my Firestore database, there is a collection named events
consisting of documents with attributes such as begin
, end
, and title
. The function in question is triggered when any changes occur within a document.
The begin
and end
fields are both categorized as type timestamp
. My objective is for the function to return false
if either begin
or end
has been modified.
In the cloud function script, I have implemented checks to compare the data before and after changes. Despite this, it returns true
, even if only the title
field has been altered.
const before = change.before.data()
const after = change.after.data()
//Although begin and end remain unchanged, true is unexpectedly returned
if (before?.begin == after?.begin && before?.end == after?.end) {
return false
}
return true
Strangely, when comparing milliseconds instead, the comparison works correctly:
const before = change.before.data()
const after = change.after.data()
//Even when begin and end stay the same, false is appropriately returned
if (before?.begin.toMillis() == after?.begin.toMillis() && before?.end.toMillis() == after?.end.toMillis()) {
return false
}
Why is this happening? Shouldn't it be possible to compare the Timestamp
objects directly rather than relying on a member function?