From 33e8c5254ae02fb0d4ed73eb9b0132dbbce34f80 Mon Sep 17 00:00:00 2001 From: ian fogelman Date: Tue, 13 Jul 2021 16:08:48 -0400 Subject: [PATCH] DOCSP-13855-mod-has-inconsistent-rounding --- source/reference/operator/query/mod.txt | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source/reference/operator/query/mod.txt b/source/reference/operator/query/mod.txt index 85ece0f04c7..b3a141c891c 100644 --- a/source/reference/operator/query/mod.txt +++ b/source/reference/operator/query/mod.txt @@ -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. +