BSONElement::numberInt truncates fractional part of double using C-style cast.
For Decimal values this methods uses Decimal128::toInt without any arguments.
This makes Decimal128::toInt to use kRoundTiesToEven rounding strategy (round to nearest integer).
As a result BSONElement::numberInt has different truncation/rounding rules for double and Decimal128 which can be misleading (see SERVER-32960).
Same is valid for BSONElement::numberLong
The best fix is to default these methods to rounding toward zero. Examination of the call sites revealed a similar issue with document value.
- is related to
-
SERVER-44618 Quarantine logic which allows generating hashed index keys with arrays when index version number is bumped
- Backlog