$exists¶
-
$exists
¶ Syntax:
{ field: { $exists: <boolean> } }
$exists
selects the documents that contain the field if<boolean>
istrue
. If<boolean>
isfalse
, the query only returns the documents that do not contain the field. Documents that contain the field but has the valuenull
are not returned.MongoDB $exists does not correspond to SQL operator
exists
. For SQLexists
, refer to the$in
operator.Consider the following example:
This query will select all documents in the
inventory
collection where theqty
field exists and its value does not equal either5
nor15
.