File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -455,6 +455,9 @@ Different query operators treat ``null`` values differently:
455
455
456
456
.. code-block:: javascript
457
457
458
+ { "_id" : 1, "cancelDate" : null }
459
+ { "_id" : 2 }
460
+
458
461
- The ``{ cancelDate : { $type: 10 } }`` query matches documents that
459
462
contains the ``cancelDate`` field whose value is ``null`` *only*;
460
463
i.e. the value of the ``cancelDate`` field is of BSON Type ``Null``
@@ -471,13 +474,14 @@ Different query operators treat ``null`` values differently:
471
474
{ "_id" : 1, "cancelDate" : null }
472
475
473
476
- The ``{ cancelDate : { $exists: false } }`` query matches documents
474
- that that do not contain the ``cancelDate`` field:
477
+ that do not contain the ``cancelDate`` field:
475
478
476
479
.. code-block:: javascript
477
480
478
481
db.test.find( { cancelDate : { $exists: false } } )
479
482
480
- The query returns only the document that contains the ``null`` value:
483
+ The query returns only the document that does *not* contain the
484
+ ``cancelDate`` field:
481
485
482
486
.. code-block:: javascript
483
487
Original file line number Diff line number Diff line change 6
6
7
7
.. operator:: $exists
8
8
9
- *Syntax*: ``{ field: { $exists: boolean } }``
9
+ *Syntax*: ``{ field: { $exists: < boolean> } }``
10
10
11
- :operator:`$exists` selects the documents that contain the field.
11
+ :operator:`$exists` selects the documents that contain the field if
12
+ ``<boolean>`` is ``true``. If ``<boolean>`` is ``false``, the query
13
+ only returns the documents that do not contain the field. Documents
14
+ that contain the field but has the value ``null`` are *not* returned.
15
+
12
16
MongoDB `$exists` does **not** correspond to SQL operator
13
17
``exists``. For SQL ``exists``, refer to the :operator:`$in`
14
18
operator.
@@ -23,13 +27,6 @@ $exists
23
27
where the ``qty`` field exists *and* its value does not equal either
24
28
``5`` nor ``15``.
25
29
26
- .. note::
27
-
28
- If set to ``false``, the query only returns those documents that
29
- do not contain the field and *not* documents that contain the
30
- field but has the value ``null``.
31
-
32
-
33
30
.. seealso::
34
31
35
32
- :method:`find() <db.collection.find()>`
You can’t perform that action at this time.
0 commit comments