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:$mod
表达式,请使用以下语法:
The $mod
operator errors when passed an array with fewer or more than two elements. $mod
运算符在传递包含少于或多于两个元素的数组时出错。See Not Enough Elements Error and Too Many Elements Error for details.有关详细信息,请参阅元素不足错误和元素过多错误。
$mod
to Select Documents$mod
选择文档¶Consider a collection 考虑一个集合inventory
with the following documents:inventory
带有以下文档:
Then, the following query selects those documents in the 然后,以下查询选择inventory
collection where value of the qty
field modulo 4
equals 0
:inventory
集合中qty
字段模4
的值等于0
的那些单据:
The query returns the following documents:查询将返回以下文档:
The $mod
operator errors when passed an array with fewer than two elements.$mod
运算符在传递少于两个元素的数组时出错。