$mod¶
-
$mod
¶ Syntax:
{ field: { $mod: [ divisor, remainder ]} }
$mod
selects the documents where thefield
value divided by thedivisor
has the specifiedremainder
.Consider the following example:
This query will select all documents in the
inventory
collection where theqty
field value modulo4
equals0
, such as documents withqty
value equal to0
or12
.In some cases, you can query using the
$mod
operator rather than the more expensive$where
operator. Consider the following example using the$mod
operator:The above query is less expensive than the following query which uses the
$where
operator: