Navigation
This version of the documentation is archived and no longer supported.

$exists

$exists

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.

←   $elemMatch (query) $gt  →