File tree 2 files changed +35
-3
lines changed
source/reference/operator
2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,13 @@ $mod (aggregation)
4
4
5
5
.. default-domain:: mongodb
6
6
7
+ .. facet::
8
+ :name: genre
9
+ :values: reference
10
+
11
+ .. meta::
12
+ :keywords: code example
13
+
7
14
.. contents:: On this page
8
15
:local:
9
16
:backlinks: none
@@ -30,6 +37,23 @@ Definition
30
37
<aggregation-expressions>` as long as they resolve to numbers. For
31
38
more information on expressions, see :ref:`aggregation-expressions`.
32
39
40
+ Starting in version 7.2, the output data type of the ``$mod`` operator is
41
+ the larger of the two input data types.
42
+
43
+ .. note::
44
+
45
+ Prior to version 7.2, the value and field type of inputs determine
46
+ the ``$mod`` output type if:
47
+
48
+ - The divisor is of data type ``double`` but has an integral
49
+ value.
50
+
51
+ - The dividend is of data type ``int`` or ``long``.
52
+
53
+ In this case, MongoDB converts the divisor to the dividend data
54
+ type before it performs the mod operation and the output data type
55
+ is the dividend data type.
56
+
33
57
Example
34
58
-------
35
59
Original file line number Diff line number Diff line change 4
4
5
5
.. default-domain:: mongodb
6
6
7
+ .. facet::
8
+ :name: genre
9
+ :values: reference
10
+
11
+ .. meta::
12
+ :keywords: code example
13
+
7
14
.. contents:: On this page
8
15
:local:
9
16
:backlinks: none
26
33
Behavior
27
34
--------
28
35
29
- The ``$mod`` operator returns an error if the ``[ divisor, remainder ]`` array
30
- contains fewer or more than two elements. For examples, see
31
- :ref:`mod-not-enough-elements` and :ref:`mod-too-many-elements` respectively.
36
+ ``$mod`` returns an error if the ``[ divisor, remainder ]`` array
37
+ doesn't contain two elements. For examples, see
38
+ :ref:`mod-not-enough-elements` and :ref:`mod-too-many-elements`
39
+ respectively.
32
40
33
41
Also, starting in MongoDB 5.1 (and 5.0.4 and 4.4.10), ``$mod``
34
42
returns an error if the ``divisor`` or ``remainder`` values evaluate to:
You can’t perform that action at this time.
0 commit comments