发布于 2015-09-14 14:59:32 | 180 次阅读 | 评论: 0 | 来源: 网络整理
Syntax: { field: { $exists: <boolean> } }
$exists selects the documents that contain the field if <boolean> is true. If <boolean> is false, the query only returns the documents that do not contain the field. Documents that contain the field but has the value null are not returned.
MongoDB $exists does not correspond to SQL operator exists. For SQL exists, refer to the $in operator.
Consider the following example:
db.inventory.find( { qty: { $exists: true, $nin: [ 5, 15 ] } } )
This query will select all documents in the inventory collection where the qty field exists and its value does not equal either 5 nor 15.