Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions source/reference/operator/query/mod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,61 @@ operator with an array that contains four elements:
"$err" : "bad query: BadValue malformed mod, too many elements",
"code" : 16810
}

Floating Point Arguments
~~~~~~~~~~~~~~~~~~~~~~~~

The ``$mod`` expression rounds decimal input towards zero.

The following examples demonstrate this behavior:

.. example::

Input query:

.. code-block:: javascript

db.inventory.find( { qty: { $mod: [ 4.0, 0 ] } } )

Results:

.. code-block:: javascript
:copyable: false

{ _id: 1, item: 'abc123', qty: 0 }
{ _id: 3, item: 'ijk123', qty: 12 }

.. example::

Input query:

.. code-block:: javascript

db.inventory.find( { qty: { $mod: [ 4.5, 0 ] } } )

Results:

.. code-block:: javascript
:copyable: false

{ _id: 1, item: 'abc123', qty: 0 }
{ _id: 3, item: 'ijk123', qty: 12 }

.. example::

Input query:

.. code-block:: javascript

db.inventory.find( { qty: { $mod: [ 4.99, 0 ] } } )

Results:

.. code-block:: javascript
:copyable: false

{ _id: 1, item: 'abc123', qty: 0 }
{ _id: 3, item: 'ijk123', qty: 12 }

Each query applies ``4`` to the ``$mod`` expression regardless of
decimal points, resulting in the same result set.