What's going on here is that JavaScript cannot natively represent 64-bit integers like -3118541015882673983
, so when converting that NumberLong
value to a JS 64-bit float it loses precision and ends up as -3118541015882674000
.
You can see this in the mongo shell:
> num = NumberLong("-3118541015882673983")
NumberLong("-3118541015882673983")
> num.toNumber()
-3118541015882674000
So in this case you're proving the _id
in the query as a 64-bit float so mongo converts the numeric doc _id
s to the same data type so that they can be compared and you get a match.