|
The problem is not specific to update, it is a more general issue with BSONElement::woCompare's handling of Date and Timestamp.
The BSON 'Date' and 'Timestamp' types have the same 'canonical type', 45: https://github.com/mongodb/mongo/blob/471bc7a3de80fae0551f164a4a0d51e2325cae30/src/mongo/bson/bsontypes.h#L143-L145
This means that if you pass a BSONElement containing a 'Date' and a BSONElement containing a 'Timestamp' to BSONElement::woCompare it will fail, since in BSONElement::woCompare the elements are forwarded to 'compareElementValues' if they have the same canonicalized type, which 'Date' and 'Timestamp' do:
https://github.com/mongodb/mongo/blob/471bc7a3de80fae0551f164a4a0d51e2325cae30/src/mongo/bson/bson-inl.h#L155-L165
However, compareElementValues requires that the elements have the same type, unless they are numeric (which Date and Timestamp are not):
https://github.com/mongodb/mongo/blob/471bc7a3de80fae0551f164a4a0d51e2325cae30/src/mongo/bson/bson-inl.h#L34-L38
As a result of breaking this invariant, when invoking BSONElement::woCompare between a Date and Timestamp element, the timestamp element will be incorrectly accessed as a date:
https://github.com/mongodb/mongo/blob/471bc7a3de80fae0551f164a4a0d51e2325cae30/src/mongo/bson/bson-inl.h#L56-L60
|