发布于 2015-09-14 14:53:28 | 94 次阅读 | 评论: 0 | 来源: 网络整理

$in

Syntax: { field: { $in: [<value1>, <value2>, ... <valueN> ] } }

$in selects the documents where the field value equals any value in the specified array (e.g. <value1>, <value2>, etc.)

Consider the following example:

db.inventory.find( { qty: { $in: [ 5, 15 ] } } )

This query selects all documents in the inventory collection where the qty field value is either 5 or 15. Although you can express this query using the $or operator, choose the $in operator rather than the $or operator when performing equality checks on the same field.

If the field holds an array, then the $in operator selects the documents whose field holds an array that contains at least one element that matches a value in the specified array (e.g. <value1>, <value2>, etc.)

Consider the following example:

db.inventory.update( { tags: { $in: ["appliances", "school"] } }, { $set: { sale:true } } )

This update() operation will set the sale field value in the inventory collection where the tags field holds an array with at least one element matching an element in the array ["appliances", "school"].

也可以参考

find(), update(), $or, $set.

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

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