Skip to content

Commit cbd983a

Browse files
committed
DOCS-800 dot-notation edits
1 parent ab47d24 commit cbd983a

File tree

7 files changed

+154
-217
lines changed

7 files changed

+154
-217
lines changed

source/applications/read.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ Consider the following examples that illustrate the use of the
124124
}
125125
)
126126

127-
*Arrays*
128-
129127
- The following operation returns all documents in the ``bios``
130128
collection where the array field ``contribs`` contains the element
131129
``'UNIX'``:
@@ -156,16 +154,10 @@ Consider the following examples that illustrate the use of the
156154
}
157155
)
158156

159-
For more examples on accessing arrays, see :ref:`query documents
160-
for arrays <document-query-arrays>` and :ref:`read operations
161-
<read-operations-dot-notation-arrays>`.
162-
163-
*Subdocuments*
164-
165157
- The following operation returns all documents in the ``bios``
166158
collection where the subdocument ``name`` contains a field
167159
``first`` with the value ``'Yukihiro'`` and a field ``last`` with
168-
the value ``'Matsumoto'``; the query uses :term:`dot-notation` to
160+
the value ``'Matsumoto'``; the query uses :term:`dot notation` to
169161
access fields in a subdocument:
170162

171163
.. code-block:: javascript
@@ -228,12 +220,6 @@ Consider the following examples that illustrate the use of the
228220
first: 'Yukihiro'
229221
}
230222

231-
For more examples on accessing subdocuments, see :ref:`query
232-
documents for subdocuments <document-query-subdocuments>` and
233-
:ref:`read operations <read-operations-dot-notation-subdocuments>`.
234-
235-
*Compound Query Criteria*
236-
237223
- The following operation returns all documents in the ``bios``
238224
collection where either the field ``first`` in the sub-document
239225
``name`` starts with the letter ``G`` **or** where the field
@@ -263,6 +249,11 @@ Consider the following examples that illustrate the use of the
263249
}
264250
)
265251

252+
The query uses the comma to specify the logical AND for criteria on
253+
different fields ``contribs`` and ``name.first``. For multiple AND
254+
criteria on the same field, use the :operator:`$and` operator
255+
instead of the comma.
256+
266257
- If there is a ``<projection>`` argument, the :method:`find()
267258
<db.collection.find()>` method returns only those fields as specified
268259
in the ``<projection>`` argument to include or exclude:
@@ -323,6 +314,15 @@ Consider the following examples that illustrate the use of the
323314
}
324315
)
325316

317+
.. seealso::
318+
319+
- :term:`dot notation` for information on dot notation
320+
321+
- :ref:`read-operations-arrays` for more examples on accessing arrays
322+
323+
- :ref:`read-operations-subdocuments` for more examples on accessing
324+
subdocuments
325+
326326
Cursor
327327
~~~~~~
328328

source/applications/update.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Consider the following examples that illustrate the use of the
7373
- If the ``<update>`` argument contains only :ref:`update operator
7474
<update-operators>` expressions such as the :operator:`$set` operator
7575
expression, the :method:`update() <db.collection.update()>` method
76-
updates the corresponding fields in the document.
76+
updates the corresponding fields in the document. To update fields in
77+
subdocuments, MongoDB uses :term:`dot notation`.
7778

7879
The following operation queries the ``bios`` collection for the first
7980
document that has an ``_id`` field equal to ``1`` and sets the field
@@ -162,7 +163,7 @@ Consider the following examples that illustrate the use of the
162163

163164
- The :method:`update() <db.collection.update()>` method can perform
164165
the update using the position of the element and
165-
:term:`dot-notation`. Arrays in MongoDB are zero-based.
166+
:term:`dot notation`. Arrays in MongoDB are zero-based.
166167

167168
The following operation queries the ``bios`` collection for
168169
the first document with ``_id`` field equal to ``1`` and updates the
@@ -196,7 +197,7 @@ Consider the following examples that illustrate the use of the
196197

197198
- The :method:`update() <db.collection.update()>` method can perform
198199
the update of an array that contains subdocuments by using the
199-
:operator:`$` positional operator and the :term:`dot-notation`.
200+
positional operator (i.e. :operator:`$`) and the :term:`dot notation`.
200201

201202
The following operation queries the ``bios`` collection for the first
202203
document where the ``_id`` field equals ``6`` and the ``awards``

source/core/document.txt

Lines changed: 65 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ the following structure:
5656
fieldN: valueN
5757
}
5858

59-
Having support for the full range of :term:`BSON types`, MongoDB
60-
documents may contain field and value pairs where the value can be
61-
another document, an array, an array of documents as well as the basic
62-
types such as ``Double``, ``String``, and ``Date``. See also
59+
Having support for the full range of BSON types, MongoDB documents may
60+
contain field and value pairs where the value can be another document,
61+
an array, an array of documents as well as the basic types such as
62+
``Double``, ``String``, and ``Date``. See also
6363
:ref:`document-bson-type-considerations`.
6464

6565
Consider the following document that contains values of varying types:
@@ -88,6 +88,11 @@ The document contains the following fields:
8888

8989
- ``views`` that holds a value of *NumberLong* type.
9090

91+
.. _document-type-operators:
92+
93+
Type Operators
94+
~~~~~~~~~~~~~~
95+
9196
To determine the type of fields, the :program:`mongo` shell provides
9297
the following operators:
9398

@@ -119,6 +124,24 @@ the following operators:
119124
In this case ``typeof`` will return the more generic ``object``
120125
type rather than ``ObjectId`` type.
121126

127+
.. _document-dot-notation:
128+
129+
Dot Notation
130+
~~~~~~~~~~~~
131+
132+
.. include:: /includes/fact-dot-notation.rst
133+
134+
.. seealso::
135+
136+
- :ref:`read-operations-subdocuments` for dot notation examples
137+
with subdocuments.
138+
139+
- :ref:`read-operations-arrays` for dot notation examples with
140+
arrays.
141+
142+
- :ref:`read-operations-arrays-of-subdocuments` for dot notation
143+
examples with arrays of subdocuments.
144+
122145
Document Types in MongoDB
123146
-------------------------
124147

@@ -215,121 +238,11 @@ Query Specification Documents
215238
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216239

217240
Query documents specify the conditions that determine which records to
218-
select for read, update, and delete operations. You can use field and
219-
value expressions to specify the equality condition and :doc:`query
220-
operator </reference/operators>` expressions to specify additional
221-
conditions. Refer to :doc:`read </applications/read>`, :doc:`update
222-
</applications/update>`, and :doc:`delete </applications/delete>` pages
223-
for more examples.
224-
225-
Consider the following examples of query documents:
226-
227-
- The following document specifies the query criteria where ``_id`` is
228-
equal to ``1``:
229-
230-
.. code-block:: javascript
231-
232-
{ _id: 1 }
233-
234-
- The following document specifies the query criteria where ``_id`` is
235-
greater than ``3``:
236-
237-
.. code-block:: javascript
238-
239-
{ _id: { $gt: 3 } }
240-
241-
- The following document specifies the compound query criteria where
242-
``_id`` is equal to ``1`` **and** the ``name`` field equals the
243-
document ``{ first: 'John', last: 'Backus' }``:
244-
245-
.. code-block:: javascript
246-
247-
{ _id: 1, name: { first: 'John', last: 'Backus' } }
248-
249-
The ``name`` field must match the document exactly, including the
250-
order of the fields.
251-
252-
- The following document specifies the compound query criteria where
253-
``_id`` is equal to ``1`` **or** the ``name`` field equals the
254-
document ``{ first: 'John', last: 'Backus' }``:
255-
256-
.. code-block:: javascript
257-
258-
{ $or: [ { _id: 1 }, { name: { first: 'John', last: 'Backus' } } ] }
259-
260-
The ``name`` field must match the document exactly, including the
261-
order of the fields.
262-
263-
.. _document-query-arrays:
264-
265-
*Query Documents for Arrays*
266-
267-
You can specify query criteria for arrays at the array level and, with
268-
:term:`dot-notation`, at the element level:
269-
270-
- The following document specifies the query criteria where
271-
``contribs`` matches exactly the array ``[ 'Fortran', 'ALGOL',
272-
'Backus-Naur Form', 'FP' ]``, including the order of the elements:
273-
274-
.. code-block:: javascript
275-
276-
{ contribs: [ 'Fortran', 'ALGOL', 'Backus-Naur Form', 'FP' ] }
277-
278-
- The following document specifies the query criteria where the value
279-
of ``contribs`` is an array that contains as one of its element
280-
``'ALGOL'``:
281-
282-
.. code-block:: javascript
283-
284-
{ contribs: 'ALGOL' }
285-
286-
- The following document specifies the query criteria where
287-
``contribs`` contains an element ``'ALGOL'`` in the second position.
288-
Array indexes are zero-based:
289-
290-
.. code-block:: javascript
291-
292-
{ 'contribs.1': 'ALGOL' }
293-
294-
See :ref:`read operations <read-operations-dot-notation-arrays>` for more
295-
examples with arrays.
296-
297-
.. _document-query-subdocuments:
298-
299-
*Query Documents for Subdocuments*
300-
301-
You can specify query criteria for subdocuments at the subdocument
302-
level and, with :term:`dot-notation`, at the field level:
303-
304-
- The following document specifies the query criteria where the value
305-
of the field ``name`` is a subdocument that contains *only* the field
306-
``first`` equal to ``'John'`` and the field ``last`` equal to
307-
``'Backus'``, in that order.
308-
309-
.. code-block:: javascript
310-
311-
{ name: { first: 'John', last: 'Backus' } }
241+
select for read, update, and delete operations. You can use
242+
``<field>:<value>`` expressions to specify the equality condition and
243+
:doc:`query operator </reference/operators>` expressions to specify
244+
additional conditions.
312245

313-
- The following document specifies the query criteria where the value
314-
of the field ``name`` is a subdocument that contains the field
315-
``first`` equal to ``'John'`` and may contain other fields:
316-
317-
.. code-block:: javascript
318-
319-
{ 'name.first': 'John' }
320-
321-
- The following document specifies the query criteria where the value
322-
of the field ``awards`` is an array that contains, as one of its
323-
elements, a subdocument that contains the field ``award`` equal to
324-
``'National Medal of Science'`` and may contain other fields:
325-
326-
.. code-block:: javascript
327-
328-
{ 'awards.award': 'National Medal of Science' }
329-
330-
See :ref:`read operations <read-operations-dot-notation-subdocuments>` for
331-
more examples with subdocuments.
332-
333246
When passed as an argument to methods such as the :method:`find()
334247
<db.collection.find()>` method, the :method:`remove()
335248
<db.collection.remove()>` method, or the :method:`update()
@@ -341,7 +254,20 @@ for MongoDB to return, remove, or update, as in the following:
341254
db.bios.find( { _id: 1 } )
342255
db.bios.remove( { _id: { $gt: 3 } } )
343256
db.bios.update( { _id: 1, name: { first: 'John', last: 'Backus' } },
344-
... )
257+
<update>,
258+
<options> )
259+
260+
.. seealso::
261+
262+
- :ref:`read-operations-query-argument` and
263+
:doc:`/applications/read` for more examples on selecting documents
264+
for reads.
265+
266+
- :doc:`/applications/update` for more examples on
267+
selecting documents for updates.
268+
269+
- :doc:`/applications/delete` for more examples on selecting
270+
documents for deletes.
345271

346272
.. _documents-update-actions:
347273

@@ -352,14 +278,14 @@ Update documents specify the data modifications to perform during
352278
an :method:`update() <db.collection.update()>` operation to modify
353279
existing records in a collection. You can use :ref:`update operators
354280
<update-operators>` to specify the exact actions to perform on the
355-
document fields. See the :ref:`update operators <update-operators>`
356-
page for the available update operators and syntax.
281+
document fields.
357282

358283
Consider the update document example:
359284

360285
.. code-block:: javascript
361286

362-
{ $set: { 'name.middle': 'Warner' },
287+
{
288+
$set: { 'name.middle': 'Warner' },
363289
$push: { awards: { award: 'IBM Fellow',
364290
year: '1963',
365291
by: 'IBM' }
@@ -371,8 +297,8 @@ When passed as an argument to the :method:`update()
371297

372298
- Modifies the field ``name`` whose value is another document.
373299
Specifically, the :operator:`$set` operator updates the ``middle``
374-
field in the ``name`` subdocument. The document uses
375-
:term:`dot-notation` to access a field in a subdocument.
300+
field in the ``name`` subdocument. The document uses :ref:`dot
301+
notation <document-dot-notation>` to access a field in a subdocument.
376302

377303
- Adds an element to the field ``awards`` whose value is an array.
378304
Specifically, the :operator:`$push` operator adds another document as
@@ -382,7 +308,8 @@ When passed as an argument to the :method:`update()
382308

383309
db.bios.update(
384310
{ _id: 1 },
385-
{ $set: { 'name.middle': 'Warner' },
311+
{
312+
$set: { 'name.middle': 'Warner' },
386313
$push: { awards: {
387314
award: 'IBM Fellow',
388315
year: '1963',
@@ -392,6 +319,14 @@ When passed as an argument to the :method:`update()
392319
}
393320
)
394321

322+
.. seealso::
323+
324+
- :ref:`update operators <update-operators>` page for the available
325+
update operators and syntax.
326+
327+
- :doc:`update </applications/update>` for more examples on
328+
update documents.
329+
395330
For additional examples of updates that involve array elements,
396331
including where the elements are documents, see the :operator:`$`
397332
positional operator.
@@ -418,8 +353,9 @@ Index documents contain field and value pairs, in the following form:
418353

419354
The following document specifies the :ref:`multi-key index
420355
<index-type-multi-key>` on the ``_id`` field and the ``last`` field
421-
contained in the subdocument ``name`` field; the document uses
422-
:term:`dot-notation` to access a field in a subdocument:
356+
contained in the subdocument ``name`` field. The document uses
357+
:ref:`dot notation <document-dot-notation>` to access a field in a
358+
subdocument:
423359

424360
.. code-block:: javascript
425361

@@ -478,8 +414,8 @@ method, the sort order document sorts the results of the
478414
.. _document-mongodb-type-considerations:
479415
.. _document-bson-type-considerations:
480416

481-
BSON Types
482-
----------
417+
BSON Type Considerations
418+
------------------------
483419

484420
The following BSON types require special consideration:
485421

0 commit comments

Comments
 (0)