$exists¶
-
$exists¶ Syntax:
{ field: { $exists: <boolean> } }$existsselects 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 valuenullare not returned.MongoDB $exists does not correspond to SQL operator
exists. For SQLexists, refer to the$inoperator.Consider the following example:
This query will select all documents in the
inventorycollection where theqtyfield exists and its value does not equal either5nor15.