@@ -56,10 +56,10 @@ the following structure:
56
56
fieldN: valueN
57
57
}
58
58
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
63
63
:ref:`document-bson-type-considerations`.
64
64
65
65
Consider the following document that contains values of varying types:
@@ -79,7 +79,7 @@ The document contains the following fields:
79
79
80
80
- ``_id`` that holds an *ObjectId*.
81
81
82
- - ``name`` that holds a *sub-document * that contains the fields
82
+ - ``name`` that holds a *subdocument * that contains the fields
83
83
``first`` and ``last``.
84
84
85
85
- ``birth`` and ``death``, which both have *Date* types.
@@ -88,6 +88,11 @@ The document contains the following fields:
88
88
89
89
- ``views`` that holds a value of *NumberLong* type.
90
90
91
+ .. _document-type-operators:
92
+
93
+ Type Operators
94
+ ~~~~~~~~~~~~~~
95
+
91
96
To determine the type of fields, the :program:`mongo` shell provides
92
97
the following operators:
93
98
@@ -119,6 +124,21 @@ the following operators:
119
124
In this case ``typeof`` will return the more generic ``object``
120
125
type rather than ``ObjectId`` type.
121
126
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
+
122
142
Document Types in MongoDB
123
143
-------------------------
124
144
@@ -215,44 +235,10 @@ Query Specification Documents
215
235
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216
236
217
237
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 following document specifies the compound query criteria where
250
- ``_id`` is equal to ``1`` **or** the ``name`` field equals the
251
- document ``{ first: 'John', last: 'Backus' }``:
252
-
253
- .. code-block:: javascript
254
-
255
- { $or: [ { _id: 1 }, { name: { first: 'John', last: 'Backus' } } ] }
238
+ select for read, update, and delete operations. You can use
239
+ ``<field>:<value>`` expressions to specify the equality condition and
240
+ :doc:`query operator </reference/operators>` expressions to specify
241
+ additional conditions.
256
242
257
243
When passed as an argument to methods such as the :method:`find()
258
244
<db.collection.find()>` method, the :method:`remove()
@@ -265,7 +251,20 @@ for MongoDB to return, remove, or update, as in the following:
265
251
db.bios.find( { _id: 1 } )
266
252
db.bios.remove( { _id: { $gt: 3 } } )
267
253
db.bios.update( { _id: 1, name: { first: 'John', last: 'Backus' } },
268
- ... )
254
+ <update>,
255
+ <options> )
256
+
257
+ .. seealso::
258
+
259
+ - :ref:`read-operations-query-argument` and
260
+ :doc:`/applications/read` for more examples on selecting documents
261
+ for reads.
262
+
263
+ - :doc:`/applications/update` for more examples on
264
+ selecting documents for updates.
265
+
266
+ - :doc:`/applications/delete` for more examples on selecting
267
+ documents for deletes.
269
268
270
269
.. _documents-update-actions:
271
270
@@ -276,14 +275,14 @@ Update documents specify the data modifications to perform during
276
275
an :method:`update() <db.collection.update()>` operation to modify
277
276
existing records in a collection. You can use :ref:`update operators
278
277
<update-operators>` to specify the exact actions to perform on the
279
- document fields. See the :ref:`update operators <update-operators>`
280
- page for the available update operators and syntax.
278
+ document fields.
281
279
282
280
Consider the update document example:
283
281
284
282
.. code-block:: javascript
285
283
286
- { $set: { 'name.middle': 'Warner' },
284
+ {
285
+ $set: { 'name.middle': 'Warner' },
287
286
$push: { awards: { award: 'IBM Fellow',
288
287
year: '1963',
289
288
by: 'IBM' }
@@ -295,7 +294,8 @@ When passed as an argument to the :method:`update()
295
294
296
295
- Modifies the field ``name`` whose value is another document.
297
296
Specifically, the :operator:`$set` operator updates the ``middle``
298
- field in the ``name`` subdocument.
297
+ field in the ``name`` subdocument. The document uses :ref:`dot
298
+ notation <document-dot-notation>` to access a field in a subdocument.
299
299
300
300
- Adds an element to the field ``awards`` whose value is an array.
301
301
Specifically, the :operator:`$push` operator adds another document as
@@ -305,7 +305,8 @@ When passed as an argument to the :method:`update()
305
305
306
306
db.bios.update(
307
307
{ _id: 1 },
308
- { $set: { 'name.middle': 'Warner' },
308
+ {
309
+ $set: { 'name.middle': 'Warner' },
309
310
$push: { awards: {
310
311
award: 'IBM Fellow',
311
312
year: '1963',
@@ -315,6 +316,18 @@ When passed as an argument to the :method:`update()
315
316
}
316
317
)
317
318
319
+ .. seealso::
320
+
321
+ - :ref:`update operators <update-operators>` page for the available
322
+ update operators and syntax.
323
+
324
+ - :doc:`update </applications/update>` for more examples on
325
+ update documents.
326
+
327
+ For additional examples of updates that involve array elements,
328
+ including where the elements are documents, see the :operator:`$`
329
+ positional operator.
330
+
318
331
.. _documents-index:
319
332
.. _document-index-specification:
320
333
@@ -335,9 +348,11 @@ Index documents contain field and value pairs, in the following form:
335
348
336
349
- ``value`` is either 1 for ascending or -1 for descending.
337
350
338
- The following document specifies the :ref:`multi-key index <index-type-multi-key>` on the ``_id``
339
- field and the ``last`` field contained in the subdocument ``name``
340
- field:
351
+ The following document specifies the :ref:`multi-key index
352
+ <index-type-multi-key>` on the ``_id`` field and the ``last`` field
353
+ contained in the subdocument ``name`` field. The document uses
354
+ :ref:`dot notation <document-dot-notation>` to access a field in a
355
+ subdocument:
341
356
342
357
.. code-block:: javascript
343
358
@@ -355,7 +370,6 @@ the index to create:
355
370
</core/read-operations>` and :doc:`write </core/write-operations>`
356
371
operations.
357
372
358
-
359
373
.. _documents-sort-order:
360
374
361
375
Sort Order Specification Documents
@@ -397,8 +411,8 @@ method, the sort order document sorts the results of the
397
411
.. _document-mongodb-type-considerations:
398
412
.. _document-bson-type-considerations:
399
413
400
- BSON Types
401
- ----------
414
+ BSON Type Considerations
415
+ ------------------------
402
416
403
417
The following BSON types require special consideration:
404
418
0 commit comments