$mod¶
-
$mod¶ Syntax:
{ field: { $mod: [ divisor, remainder ]} }$modselects the documents where thefieldvalue divided by thedivisorhas the specifiedremainder.Consider the following example:
This query will select all documents in the
inventorycollection where theqtyfield value modulo4equals0, such as documents withqtyvalue equal to0or12.In some cases, you can query using the
$modoperator rather than the more expensive$whereoperator. Consider the following example using the$modoperator:The above query is less expensive than the following query which uses the
$whereoperator: