-
Notifications
You must be signed in to change notification settings - Fork 1.7k
DOCS-800 added dot notation documentation #433
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ The document contains the following fields: | |
|
||
- ``_id`` that holds an *ObjectId*. | ||
|
||
- ``name`` that holds a *sub-document* that contains the fields | ||
- ``name`` that holds a *subdocument* that contains the fields | ||
``first`` and ``last``. | ||
|
||
- ``birth`` and ``death``, which both have *Date* types. | ||
|
@@ -246,6 +246,9 @@ Consider the following examples of query documents: | |
|
||
{ _id: 1, name: { first: 'John', last: 'Backus' } } | ||
|
||
The ``name`` field must match the document exactly, including the | ||
order of the fields. | ||
|
||
- The following document specifies the compound query criteria where | ||
``_id`` is equal to ``1`` **or** the ``name`` field equals the | ||
document ``{ first: 'John', last: 'Backus' }``: | ||
|
@@ -254,6 +257,79 @@ Consider the following examples of query documents: | |
|
||
{ $or: [ { _id: 1 }, { name: { first: 'John', last: 'Backus' } } ] } | ||
|
||
The ``name`` field must match the document exactly, including the | ||
order of the fields. | ||
|
||
.. _document-query-arrays: | ||
|
||
*Query Documents for Arrays* | ||
|
||
You can specify query criteria for arrays at the array level and, with | ||
:term:`dot-notation`, at the element level: | ||
|
||
- The following document specifies the query criteria where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every other sentence begins with the words "the following" which is consistent but also makes things easier to not read and therefore miss/skip over |
||
``contribs`` matches exactly the array ``[ 'Fortran', 'ALGOL', | ||
'Backus-Naur Form', 'FP' ]``, including the order of the elements: | ||
|
||
.. code-block:: javascript | ||
|
||
{ contribs: [ 'Fortran', 'ALGOL', 'Backus-Naur Form', 'FP' ] } | ||
|
||
- The following document specifies the query criteria where the value | ||
of ``contribs`` is an array that contains as one of its element | ||
``'ALGOL'``: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To select an array given the value of one of it's components, use a query document that resembles:
If |
||
|
||
.. code-block:: javascript | ||
|
||
{ contribs: 'ALGOL' } | ||
|
||
- The following document specifies the query criteria where | ||
``contribs`` contains an element ``'ALGOL'`` in the second position. | ||
Array indexes are zero-based: | ||
|
||
.. code-block:: javascript | ||
|
||
{ 'contribs.1': 'ALGOL' } | ||
|
||
See :ref:`read operations <read-operations-dot-notation-arrays>` for more | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "See read operations for more information" doesn't quite read right? |
||
examples with arrays. | ||
|
||
.. _document-query-subdocuments: | ||
|
||
*Query Documents for Subdocuments* | ||
|
||
You can specify query criteria for subdocuments at the subdocument | ||
level and, with :term:`dot-notation`, at the field level: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd drop the hyphen in dot-notation it'll work fine. |
||
|
||
- The following document specifies the query criteria where the value | ||
of the field ``name`` is a subdocument that contains *only* the field | ||
``first`` equal to ``'John'`` and the field ``last`` equal to | ||
``'Backus'``, in that order. | ||
|
||
.. code-block:: javascript | ||
|
||
{ name: { first: 'John', last: 'Backus' } } | ||
|
||
- The following document specifies the query criteria where the value | ||
of the field ``name`` is a subdocument that contains the field | ||
``first`` equal to ``'John'`` and may contain other fields: | ||
|
||
.. code-block:: javascript | ||
|
||
{ 'name.first': 'John' } | ||
|
||
- The following document specifies the query criteria where the value | ||
of the field ``awards`` is an array that contains, as one of its | ||
elements, a subdocument that contains the field ``award`` equal to | ||
``'National Medal of Science'`` and may contain other fields: | ||
|
||
.. code-block:: javascript | ||
|
||
{ 'awards.award': 'National Medal of Science' } | ||
|
||
See :ref:`read operations <read-operations-dot-notation-subdocuments>` for | ||
more examples with subdocuments. | ||
|
||
When passed as an argument to methods such as the :method:`find() | ||
<db.collection.find()>` method, the :method:`remove() | ||
<db.collection.remove()>` method, or the :method:`update() | ||
|
@@ -295,7 +371,8 @@ When passed as an argument to the :method:`update() | |
|
||
- Modifies the field ``name`` whose value is another document. | ||
Specifically, the :operator:`$set` operator updates the ``middle`` | ||
field in the ``name`` subdocument. | ||
field in the ``name`` subdocument. The document uses | ||
:term:`dot-notation` to access a field in a subdocument. | ||
|
||
- Adds an element to the field ``awards`` whose value is an array. | ||
Specifically, the :operator:`$push` operator adds another document as | ||
|
@@ -315,6 +392,10 @@ When passed as an argument to the :method:`update() | |
} | ||
) | ||
|
||
For additional examples of updates that involve array elements, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think burrying the cross reference at the end of pargraphs like this is probably less than ideal, and is probably a little wordy. |
||
including where the elements are documents, see the :operator:`$` | ||
positional operator. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the positional operatior (i.e. |
||
|
||
.. _documents-index: | ||
.. _document-index-specification: | ||
|
||
|
@@ -335,9 +416,10 @@ Index documents contain field and value pairs, in the following form: | |
|
||
- ``value`` is either 1 for ascending or -1 for descending. | ||
|
||
The following document specifies the :ref:`multi-key index <index-type-multi-key>` on the ``_id`` | ||
field and the ``last`` field contained in the subdocument ``name`` | ||
field: | ||
The following document specifies the :ref:`multi-key index | ||
<index-type-multi-key>` on the ``_id`` field and the ``last`` field | ||
contained in the subdocument ``name`` field; the document uses | ||
:term:`dot-notation` to access a field in a subdocument: | ||
|
||
.. code-block:: javascript | ||
|
||
|
@@ -355,7 +437,6 @@ the index to create: | |
</core/read-operations>` and :doc:`write </core/write-operations>` | ||
operations. | ||
|
||
|
||
.. _documents-sort-order: | ||
|
||
Sort Order Specification Documents | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these italicized bits need to be subheadings. change throughout.