-
Type: Task
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: manual
-
Labels:
$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. $exists does match documents that contain the field that stores the null value.
When you specify true to the $exists operator, the query will select documents where the value of the specified field is null. If you specify false to $exists, the query will not match fields that hold the null value.
The second paragraph seems redundant and the second sentence is particularly confusing since we're dealing with a double negative (false value and "not match").
The boolean argument for $exists only determines whether the field, irrespective of its value, should exist in the document. Maybe adding that in the first paragraph will increase readability:
If <boolean> is true, $exists matches the documents that contain the field. If <boolean> is false, the query only returns the documents that do not contain the field. $exists only considers whether a field is present in the document, irrespective of its value (e.g. { $exists: true } would match a field with a null value).
Here, I think it's also more consistent to refer to query operators "matching" documents rather than "selecting" them. A document is ultimately selected for the result set when a logical combination of its query operators match (after any and/or logic).