diff --git a/source/images/compass-find-null-existence-check.png b/source/images/compass-find-null-existence-check.png new file mode 100644 index 00000000000..7dcf821a151 Binary files /dev/null and b/source/images/compass-find-null-existence-check.png differ diff --git a/source/images/compass-find-null-field.png b/source/images/compass-find-null-field.png new file mode 100644 index 00000000000..c30edfb2032 Binary files /dev/null and b/source/images/compass-find-null-field.png differ diff --git a/source/images/compass-find-null-type-check.png b/source/images/compass-find-null-type-check.png new file mode 100644 index 00000000000..18f0ea21cfb Binary files /dev/null and b/source/images/compass-find-null-type-check.png differ diff --git a/source/includes/driver-example-query-38.rst b/source/includes/driver-example-query-38.rst index 857858add27..d59b8653b87 100644 --- a/source/includes/driver-example-query-38.rst +++ b/source/includes/driver-example-query-38.rst @@ -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 `. + - id: python content: | .. class:: copyable-code diff --git a/source/includes/driver-example-query-39.rst b/source/includes/driver-example-query-39.rst index f6ad47b4ee6..821bc64fad4 100644 --- a/source/includes/driver-example-query-39.rst +++ b/source/includes/driver-example-query-39.rst @@ -8,6 +8,19 @@ db.inventory.find( { item: null } ) + - id: compass + content: | + Copy the following query filter document into the + :ref:`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 diff --git a/source/includes/driver-example-query-40.rst b/source/includes/driver-example-query-40.rst index 2aeaaf3f0cb..d0b080acdc1 100644 --- a/source/includes/driver-example-query-40.rst +++ b/source/includes/driver-example-query-40.rst @@ -8,6 +8,19 @@ db.inventory.find( { item : { $type: 10 } } ) + - id: compass + content: | + Copy the following query filter document into the + :ref:`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 diff --git a/source/includes/driver-example-query-41.rst b/source/includes/driver-example-query-41.rst index 9aefe10fa08..85761c20e6f 100644 --- a/source/includes/driver-example-query-41.rst +++ b/source/includes/driver-example-query-41.rst @@ -8,6 +8,19 @@ db.inventory.find( { item : { $exists: false } } ) + - id: compass + content: | + Copy the following query filter document into the + :ref:`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 diff --git a/source/includes/driver-example-query-intro.rst b/source/includes/driver-example-query-intro.rst index 3d7b5639918..c4cb68c900e 100644 --- a/source/includes/driver-example-query-intro.rst +++ b/source/includes/driver-example-query-intro.rst @@ -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 `. 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 diff --git a/source/tutorial/query-for-null-fields.txt b/source/tutorial/query-for-null-fields.txt index 0c1aeb2b1b1..f6b16432634 100644 --- a/source/tutorial/query-for-null-fields.txt +++ b/source/tutorial/query-for-null-fields.txt @@ -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 @@ -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 ---------- @@ -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 ` ``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 ` ``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 ` ``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 ` ``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 ` ``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 ` ``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 ` ``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 ` ``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 ` ``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 ` ``Null`` + (type number ``10``) : - id: csharp content: | - The ``Type("item", BsonType.Null)`` query using the :csharp-api:`FilterDefinitionBuilder.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() + ` + 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 ` ``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 --------------- @@ -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 @@ -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.