Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-2652

Suggestion for /manual/reference/operator/query/exists/

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • v1.3.1
    • 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).

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              10 years, 10 weeks, 4 days ago