@@ -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:
@@ -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,24 @@ 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
+
142
+ - :ref:`read-operations-arrays-of-subdocuments` for dot notation
143
+ examples with arrays of subdocuments.
144
+
122
145
Document Types in MongoDB
123
146
-------------------------
124
147
@@ -215,121 +238,11 @@ Query Specification Documents
215
238
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216
239
217
240
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.
312
245
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
-
333
246
When passed as an argument to methods such as the :method:`find()
334
247
<db.collection.find()>` method, the :method:`remove()
335
248
<db.collection.remove()>` method, or the :method:`update()
@@ -341,7 +254,20 @@ for MongoDB to return, remove, or update, as in the following:
341
254
db.bios.find( { _id: 1 } )
342
255
db.bios.remove( { _id: { $gt: 3 } } )
343
256
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.
345
271
346
272
.. _documents-update-actions:
347
273
@@ -352,14 +278,14 @@ Update documents specify the data modifications to perform during
352
278
an :method:`update() <db.collection.update()>` operation to modify
353
279
existing records in a collection. You can use :ref:`update operators
354
280
<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.
357
282
358
283
Consider the update document example:
359
284
360
285
.. code-block:: javascript
361
286
362
- { $set: { 'name.middle': 'Warner' },
287
+ {
288
+ $set: { 'name.middle': 'Warner' },
363
289
$push: { awards: { award: 'IBM Fellow',
364
290
year: '1963',
365
291
by: 'IBM' }
@@ -371,8 +297,8 @@ When passed as an argument to the :method:`update()
371
297
372
298
- Modifies the field ``name`` whose value is another document.
373
299
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.
376
302
377
303
- Adds an element to the field ``awards`` whose value is an array.
378
304
Specifically, the :operator:`$push` operator adds another document as
@@ -382,7 +308,8 @@ When passed as an argument to the :method:`update()
382
308
383
309
db.bios.update(
384
310
{ _id: 1 },
385
- { $set: { 'name.middle': 'Warner' },
311
+ {
312
+ $set: { 'name.middle': 'Warner' },
386
313
$push: { awards: {
387
314
award: 'IBM Fellow',
388
315
year: '1963',
@@ -392,6 +319,14 @@ When passed as an argument to the :method:`update()
392
319
}
393
320
)
394
321
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
+
395
330
For additional examples of updates that involve array elements,
396
331
including where the elements are documents, see the :operator:`$`
397
332
positional operator.
@@ -418,8 +353,9 @@ Index documents contain field and value pairs, in the following form:
418
353
419
354
The following document specifies the :ref:`multi-key index
420
355
<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:
423
359
424
360
.. code-block:: javascript
425
361
@@ -478,8 +414,8 @@ method, the sort order document sorts the results of the
478
414
.. _document-mongodb-type-considerations:
479
415
.. _document-bson-type-considerations:
480
416
481
- BSON Types
482
- ----------
417
+ BSON Type Considerations
418
+ ------------------------
483
419
484
420
The following BSON types require special consideration:
485
421
0 commit comments