Skip to content

DOCSP-1379 - Integrate Compass into Query Array of Docs tutorial #3120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2017
Merged
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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-nested-in-array.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions source/includes/driver-example-query-29.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@

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

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

[
{ item: "journal", instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] },
{ item: "notebook", instock: [ { warehouse: "C", qty: 5 } ] },
{ item: "paper", instock: [ { warehouse: "A", qty: 60 }, { warehouse: "B", qty: 15 } ] },
{ item: "planner", instock: [ { warehouse: "A", qty: 40 }, { warehouse: "B", qty: 5 } ] },
{ item: "postcard", instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ] }
]

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

- id: python
content: |
.. class:: copyable-code
Expand Down
12 changes: 12 additions & 0 deletions source/includes/driver-example-query-30.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
db.inventory.find( { "instock": { warehouse: "A", qty: 5 } } )
- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

.. class:: copyable-code
.. code-block:: javascript
{ "instock": { warehouse: "A", qty: 5 } }
.. figure:: /images/compass-find-nested-in-array.png

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

db.inventory.find( { "instock": { qty: 5, warehouse: "A" } } )

- id: compass
content: |
.. figure:: /images/compass-find-nested-array-no-match.png

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

db.inventory.find( { 'instock.0.qty': { $lte: 20 } } )

- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

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

{ 'instock.0.qty': { $lte: 20 } }

.. figure:: /images/compass-find-array-index-embedded-doc.png

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

db.inventory.find( { 'instock.qty': { $lte: 20 } } )

- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

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

{ 'instock.qty': { $lte: 20 } }

.. figure:: /images/compass-find-array-embedded-field-condition.png

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

db.inventory.find( { "instock": { $elemMatch: { qty: 5, warehouse: "A" } } } )

- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

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

{ "instock": { $elemMatch: { qty: 5, warehouse: "A" } } }

.. figure:: /images/compass-array-multiple-cond-single-doc.png

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

db.inventory.find( { "instock": { $elemMatch: { qty: { $gt: 10, $lte: 20 } } } } )

- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

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

{ "instock": { $elemMatch: { qty: { $gt: 10, $lte: 20 } } } }

.. figure:: /images/compass-array-multiple-cond-single-doc-2.png

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

db.inventory.find( { "instock.qty": { $gt: 10, $lte: 20 } } )

- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

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

{ "instock.qty": { $gt: 10, $lte: 20 } }

.. figure:: /images/compass-array-match-combination-of-elements.png

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

db.inventory.find( { "instock.qty": 5, "instock.warehouse": "A" } )

- id: compass
content: |
Copy the following filter into the Compass query bar and click
:guilabel:`Find`:

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

{ "instock.qty": 5, "instock.warehouse": "A" }

.. figure:: /images/compass-array-match-combination-of-elements-2.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| in
: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
33 changes: 19 additions & 14 deletions source/tutorial/query-array-of-documents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Query an Array of Embedded Documents
Query for a Document Nested in an Array
---------------------------------------

The following examples selects all documents where an element in the
The following example selects all documents where an element in the
``instock`` array matches the specified document:

.. include:: /includes/driver-example-query-30.rst
Expand All @@ -37,19 +37,6 @@ example, the following query does not match any documents in the
Specify a Query Condition on a Field in an Array of Documents
-------------------------------------------------------------

Use the Array Index to Query for a Field in the Embedded Document
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using the :term:`dot notation`, you can specify query conditions for
field in a document at a particular index or position of the array. The
array uses zero-based indexing.

The following example selects all documents where the ``instock`` array
has as its first element a document that contains the field ``qty``
whose value is less than or equal to ``20``:

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

Specify a Query Condition on a Field Embedded in an Array of Documents
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -63,6 +50,24 @@ whose value is less than or equal to ``20``:

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

Use the Array Index to Query for a Field in the Embedded Document
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using :term:`dot notation`, you can specify query conditions for
field in a document at a particular index or position of the array. The
array uses zero-based indexing.

.. note::

When querying using dot notation, the field and index must be
inside quotation marks.

The following example selects all documents where the ``instock`` array
has as its first element a document that contains the field ``qty``
whose value is less than or equal to ``20``:

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

Specify Multiple Conditions for Array of Documents
--------------------------------------------------

Expand Down