-
Type: Investigation
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
The type of the result of a $mod expression is now determined solely from the input types; the exact input value will no longer lead to a narrower result type.
E.g., Previously $mod: [2, 1.1] would result in a double result, but $mod: [2, 1.0], would result in a integer, as the rhs happens to be convertible to an int without rounding error despite being of double type.
Now, the result type will always be the wider of the two input types.
If the existing behaviour was relied upon, users may now find that code expecting an int instead of a long or double needs to be updated to expect the appropriate type result - or to provide arguments as ints if applicable.
Description of Linked Ticket
$mod has a special condition if the right-hand-side is of non-integral type but of integral value.
https://github.com/mongodb/mongo/blob/8387824b3ac937b0489fcb94c590cc663b47348c/src/mongo/db/pipeline/expression.cpp#L2528
We should eliminate this condition from the conditional so that the output type of an arithmetic expression is based only on input types, not values. This has two benefits:
It causes a pipeline to output documents that are closer to a fixed schema.
Non-deterministicly-ordered input to grouping stages will no longer cause output of arbitrary type. This will eliminate the linked agg fuzzer issue.
- depends on
-
SERVER-39336 In order to be schema friendly, $mod output should be based only on input types, not values
- Closed