Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/compass-find-null-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/compass-find-null-type-check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions source/includes/driver-example-query-38.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@

.. include:: /includes/fact-mws.rst

- id: compass
content: |
.. code-block:: javascript

[
{ _id: 1, item: null },
{ _id: 2 }
]

For instructions on inserting documents in MongoDB Compass, see
:doc:`Insert Documents </tutorial/insert-documents/>`.

- id: python
content: |
.. class:: copyable-code
Expand Down
13 changes: 13 additions & 0 deletions source/includes/driver-example-query-39.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

db.inventory.find( { item: null } )

- id: compass
content: |
Copy the following query filter document into the
:ref:`query bar <compass-query-bar>` and click
:guilabel:`Find`:

.. class:: copyable-code
.. code-block:: javascript

{ item: null }

.. figure:: /images/compass-find-null-field.png

- id: python
content: |
.. class:: copyable-code
Expand Down
13 changes: 13 additions & 0 deletions source/includes/driver-example-query-40.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

db.inventory.find( { item : { $type: 10 } } )

- id: compass
content: |
Copy the following query filter document into the
:ref:`query bar <compass-query-bar>` and click
:guilabel:`Find`:

.. class:: copyable-code
.. code-block:: javascript

{ item : { $type: 10 } }

.. figure:: /images/compass-find-null-type-check.png

- id: python
content: |
.. class:: copyable-code
Expand Down
13 changes: 13 additions & 0 deletions source/includes/driver-example-query-41.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@

db.inventory.find( { item : { $exists: false } } )

- id: compass
content: |
Copy the following query filter document into the
:ref:`query bar <compass-query-bar>` and click
:guilabel:`Find`:

.. class:: copyable-code
.. code-block:: javascript

{ item : { $exists: false } }

.. figure:: /images/compass-find-null-existence-check.png

- id: python
content: |
.. class:: copyable-code
Expand Down
7 changes: 7 additions & 0 deletions source/includes/driver-example-query-intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
``inventory`` collection. To populate the ``inventory``
collection, run the following:

- id: compass
content: |
This page provides examples of |query_operations| using
:ref:`MongoDB Compass <compass-index>`. The examples on this
page use the ``inventory`` collection. Populate the
``inventory`` collection with the following documents:

- id: python
content: |
This page provides examples of |query_operations| using the
Expand Down
124 changes: 77 additions & 47 deletions source/tutorial/query-for-null-fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ Equality Filter
contain the ``item`` field whose value is ``null`` *or* that
do not contain the ``item`` field.

- id: compass
content: |
The ``{ item : null }`` query matches documents that either
contain the ``item`` field whose value is ``null`` *or* that
do not contain the ``item`` field.

- id: python
content: |
The ``{ item : None }`` query matches documents that either
Expand Down Expand Up @@ -119,10 +125,10 @@ Equality Filter
matches documents that either contain the ``item`` field whose
value is ``null`` *or* that do not contain the ``item`` field.

For example, the following query returns both documents:

.. include:: /includes/driver-example-query-39.rst

The query returns both documents in the collection.

Type Check
----------

Expand All @@ -131,79 +137,98 @@ Type Check
tabs:
- id: shell
content: |
The ``{ item : { $type: 10 } }`` query matches documents that
contains the ``item`` field whose value is ``null`` *only*;
i.e. the value of the ``item`` field is of BSON Type ``Null``
(i.e. ``10``) :
The ``{ item : { $type: 10 } }`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: compass
content: |
The ``{ item : { $type: 10 } }`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: python
content: |
The ``{ item : { $type: 10 } }`` query matches documents that
contains the ``item`` field whose value is ``null`` *only*;
i.e. the value of the ``item`` field is of BSON Type ``Null``
(i.e. ``10``) :
The ``{ item : { $type: 10 } }`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: java-sync
content: |
The ``type("item", BsonType.NULL)`` query matches documents
that contains the ``item`` field whose value is ``null``
*only*; i.e. the value of the ``item`` field is of BSON Type
``Null`` (i.e. ``10``) :
The ``type("item", BsonType.NULL)`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: java-async
content: |
The ``type("item", BsonType.NULL)`` query matches documents
that contains the ``item`` field whose value is ``null``
*only*; i.e. the value of the ``item`` field is of BSON Type
``Null`` (i.e. ``10``) :
The ``type("item", BsonType.NULL)`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: nodejs
content: |
The ``{ item : { $type: 10 } }`` query matches documents that
contains the ``item`` field whose value is ``null`` *only*;
i.e. the value of the ``item`` field is of BSON Type ``Null``
(i.e. ``10``) :
The ``{ item : { $type: 10 } }`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: php
content: |
The ``[ item => [ $type => 10 ] ]`` query matches documents that
contains the ``item`` field whose value is ``null`` *only*;
i.e. the value of the ``item`` field is of BSON Type ``Null``
(i.e. ``10``) :
The ``[ item => [ $type => 10 ] ]`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: perl
content: |
The ``{ item => { $type => 10 } }`` query matches documents that
contains the ``item`` field whose value is ``null`` *only*;
i.e. the value of the ``item`` field is of BSON Type ``Null``
(i.e. ``10``) :
The ``{ item => { $type => 10 } }`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: ruby
content: |
The ``{ item => { $type => 10 } }`` query matches documents that
contains the ``item`` field whose value is ``nil`` *only*;
i.e. the value of the ``item`` field is of BSON Type ``Null``
(i.e. ``10``) :
The ``{ item => { $type => 10 } }`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: java-sync
content: |
The ``type("item", BsonType.NULL)`` query matches documents
that contains the ``item`` field whose value is ``null``
*only*; i.e. the value of the ``item`` field is of BSON Type
``Null`` (i.e. ``10``) :
The ``type("item", BsonType.NULL)`` query matches *only*
documents that contain the ``item`` field whose value is
``null``; i.e. the value of the ``item`` field is of
:doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

- id: csharp
content: |
The ``Type("item", BsonType.Null)`` query using the :csharp-api:`FilterDefinitionBuilder.Type()
<Overload_MongoDB_Driver_FilterDefinitionBuilder_1_Type>` method
matches documents that contain the ``item`` field whose value is
``null`` *only*; i.e. the value of the ``item`` field is of BSON
Type ``Null`` (i.e. ``10``) :
The ``Type("item", BsonType.Null)`` query using the
:csharp-api:`FilterDefinitionBuilder.Type()
<Overload_MongoDB_Driver_FilterDefinitionBuilder_1_Type>`
method matches *only* documents that contain the ``item``
field whose value is ``null``; i.e. the value of the ``item``
field is of :doc:`BSON Type </reference/bson-types>` ``Null``
(type number ``10``) :

.. include:: /includes/driver-example-query-40.rst

The query returns only the document where the ``item`` field has a
``null`` value.
value of ``null``.

Existence Check
---------------
Expand All @@ -216,6 +241,11 @@ Existence Check
The ``{ item : { $exists: false } }`` query matches documents
that do not contain the ``item`` field:

- id: compass
content: |
The ``{ item : { $exists: false } }`` query matches documents
that do not contain the ``item`` field:

- id: python
content: |
The ``{ item : { $exists: False } }`` query matches documents
Expand Down Expand Up @@ -264,8 +294,8 @@ Existence Check

.. include:: /includes/driver-example-query-41.rst

The query returns only the document that does *not* contain the
``item`` field:
The query only returns the document that does *not* contain the
``item`` field.

.. seealso:: The reference documentation for the :query:`$type` and
.. seealso:: Reference documentation for the :query:`$type` and
:query:`$exists` operators.