Skip to content

DOCS-13855-mod-has-inconsistent-rounding #5558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
28 changes: 28 additions & 0 deletions source/reference/operator/query/mod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,31 @@ operator with an array that contains four elements:
"$err" : "bad query: BadValue malformed mod, too many elements",
"code" : 16810
}

Modulo with Decimal Divisors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``modulo`` expression rounds down decimal input to the floor.

The following examples demonstrates this behavior :

.. code-block:: javascript

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

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

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

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

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

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

Each query applies 4 to the mod function regardless of decimal points
resulting in the same result set.