$mod¶
On this page
-
$mod
¶ Select documents where the value of a field divided by a divisor has the specified remainder (i.e. perform a modulo operation to select documents). To specify a
$mod
expression, use the following syntax:The
$mod
operator errors when passed an array with fewer or more than two elements. See Not Enough Elements Error and Too Many Elements Error for details.
Examples¶
Use $mod
to Select Documents¶
Consider a collection inventory
with the following documents:
Then, the following query selects those documents in the
inventory
collection where value of the qty
field modulo
4
equals 0
:
The query returns the following documents: