Skip to content

Commit

Permalink
DOCS 16507 clarify output of mod operator (#5550)
Browse files Browse the repository at this point in the history
* DOCS-16507 mod output type

* DOCS-16507 adding tag

* DOCS-16507 adding tag

* DOCS-16507 adding tag

* DOCS-16507 copy edits

* DOCSP-16507 tech edit

* DOCSP-16507 tech edit

* DOCS-16507 tech edits

* DOCS-16507 tech edits

* DOCS-16507 tech edits

* Empty-Commit
  • Loading branch information
ltran-mdb2 authored Jan 16, 2024
1 parent 0d963bb commit dbfbdbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
24 changes: 24 additions & 0 deletions source/reference/operator/aggregation/mod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ $mod (aggregation)

.. default-domain:: mongodb

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example

.. contents:: On this page
:local:
:backlinks: none
Expand All @@ -30,6 +37,23 @@ Definition
<aggregation-expressions>` as long as they resolve to numbers. For
more information on expressions, see :ref:`aggregation-expressions`.

Starting in version 7.2, the output data type of the ``$mod`` operator is
the larger of the two input data types.

.. note::

Prior to version 7.2, the value and field type of inputs determine
the ``$mod`` output type if:

- The divisor is of data type ``double`` but has an integral
value.

- The dividend is of data type ``int`` or ``long``.

In this case, MongoDB converts the divisor to the dividend data
type before it performs the mod operation and the output data type
is the dividend data type.

Example
-------

Expand Down
14 changes: 11 additions & 3 deletions source/reference/operator/query/mod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ $mod

.. default-domain:: mongodb

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example

.. contents:: On this page
:local:
:backlinks: none
Expand All @@ -26,9 +33,10 @@ $mod
Behavior
--------

The ``$mod`` operator returns an error if the ``[ divisor, remainder ]`` array
contains fewer or more than two elements. For examples, see
:ref:`mod-not-enough-elements` and :ref:`mod-too-many-elements` respectively.
``$mod`` returns an error if the ``[ divisor, remainder ]`` array
doesn't contain two elements. For examples, see
:ref:`mod-not-enough-elements` and :ref:`mod-too-many-elements`
respectively.

Also, starting in MongoDB 5.1 (and 5.0.4 and 4.4.10), ``$mod``
returns an error if the ``divisor`` or ``remainder`` values evaluate to:
Expand Down

0 comments on commit dbfbdbd

Please sign in to comment.