发布于 2015-09-14 15:07:39 | 109 次阅读 | 评论: 0 | 来源: 网络整理

$mod

Syntax: { field: { $mod: [ divisor, remainder ]} }

$mod selects the documents where the field value divided by the divisor has the specified remainder.

Consider the following example:

db.inventory.find( { qty: { $mod: [ 4, 0 ] } } )

This query will select all documents in the inventory collection where the qty field value modulo 4 equals 0, such as documents with qty value equal to 0 or 12.

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:

db.inventory.find( { qty: { $mod: [ 4, 0 ] } } )

The above query is less expensive than the following query which uses the $where operator:

db.inventory.find( { $where: "this.qty % 4 == 0" } )

也可以参考

find(), update(), $set.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务