@@ -324,15 +324,14 @@ MongoDB creates a query plan as follows:
324
324
325
325
To evaluate the optimizer's choice of query plan, run the query with
326
326
the :method:`explain() <cursor.explain()>` method and the
327
- :method:`hint() <cursor.hint()>` method appended. Instead of returning
328
- query results, this returns statistics about how the query runs. For
329
- example:
327
+ :method:`hint() <cursor.hint()>` method appended, as in the following:
330
328
331
329
.. code-block:: javascript
332
330
333
331
db.inventory.find( { type: 'food' } ).explain().hint()
334
332
335
- For details on the output, see the :method:`explain()
333
+ This returns the statistics regarding the execution of the query. For a
334
+ detailed explanation on the output, see the :method:`explain()
336
335
<cursor.explain()>` method documentation.
337
336
338
337
.. note::
@@ -360,27 +359,43 @@ parallel query operation.
360
359
361
360
For more information, refer to :doc:`/applications/indexes`.
362
361
362
+ Query Operators that Cannot Use Indexes
363
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364
+
365
+ Some query operators cannot take advantage of indexes and require a
366
+ collection scan. When using these operators, you can narrow the
367
+ documents scanned by combining the operator with another operator that
368
+ does use an index.
369
+
370
+ Operators that cannot use indexes include the following:
371
+
372
+ - :operator:`$nin`
373
+
374
+ - :operator:`$ne`
375
+
376
+ .. TODO Regular expressions queries also do not use an index except when used with anchors.
377
+ .. TODO :method:`cursor.skip()` can cause paginating large numbers of docs
378
+
363
379
.. _read-operations-aggregation:
364
380
365
381
Aggregation
366
382
~~~~~~~~~~~
367
383
368
- When you run a query using aggregation, MongoDB performs summary,
369
- grouping, or other operations on data before returning results. When you
370
- run a query without aggregation, you retrieve data as it's stored in the
371
- database; when you run with aggregation, you retrieve reframed data.
384
+ With aggregation, MongoDB performs summary, grouping, or other
385
+ operations on data before returning the results.
372
386
373
387
Beginning with MongoDB version 2.1, the primary way to perform
374
388
aggregation is through the aggregation framework, which processes data
375
- through pipelines and returns data as a document stream specific to the
376
- aggregation process.
389
+ through pipelines and returns the data as a document stream specific to
390
+ the aggregation process.
377
391
378
- For more information on the aggregation framework, including
379
- descriptions of operators, see see :doc:`/applications/aggregation`.
392
+ The order of aggregation operators can affect the performance of the
393
+ query. For more information on the aggregation framework, including the
394
+ descriptions of the operators and the optimization of performance, see
395
+ :doc:`/applications/aggregation`.
380
396
381
- In addition to the operators used by the aggregation framework, you can
382
- use the following aggregation operators. For documentation on each
383
- operator, click the operator name:
397
+ Additionally, MongoDB supplements the aggregation framework with the
398
+ following methods and commands:
384
399
385
400
- :method:`count() <cursor.count()>`
386
401
@@ -393,23 +408,6 @@ operator, click the operator name:
393
408
.. index:: read operation; architecture
394
409
.. _read-operations-architecture:
395
410
396
- Query Operators that Cannot Use Indexes
397
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
398
-
399
- Some query operators cannot take advantage of indexes and require a
400
- collection scan. When using these operators you can narrow the documents
401
- scanned by combining the operator with another operator that does use an
402
- index.
403
-
404
- Operators that cannot use indexes include the following:
405
-
406
- - :operator:`$nin`
407
-
408
- - :operator:`$ne`
409
-
410
- .. TODO Regular expressions queries also do not use an index except when used with anchors.
411
- .. TODO :method:`cursor.skip()` can cause paginating large numbers of docs
412
-
413
411
Architecture
414
412
------------
415
413
@@ -422,34 +420,35 @@ Connection Pooling
422
420
423
421
.. TODO
424
422
425
- Shard Clusters
426
- ~~~~~~~~~~~~~~
423
+ Sharded Clusters
424
+ ~~~~~~~~~~~~~~~~
427
425
428
- Issue all read operations to a sharded cluster to one of the
429
- :program:`mongos` instances associated with the cluster. From the
430
- perspective of the application there is no difference between read
431
- operations to MongoDB sharded clusters and read operations to
432
- standalone instances and replica sets.
426
+ Sharded clusters allows for the distribution of the collection data
427
+ across multiple nodes. With a sharded cluster, you issue all read
428
+ operations to one of the :program:`mongos` instances associated with
429
+ the cluster. From the perspective of the application there is no
430
+ difference between read operations to the MongoDB sharded cluster and
431
+ read operations to standalone instances and replica sets.
433
432
434
433
For non-sharded collections, the :program:`mongos` locates the
435
434
:term:`primary shard` for the database, and directs all operations to
436
435
that :program:`mongod` instance. For sharded collections, the
437
- :program:`mongos` must determine which :term:`shard` may have
438
- documents that could match the query using the :term:`shard
439
- key` . Then, the :program:`mongos` can direct the query to the relevant
440
- members and merge all reseults .
441
-
442
- If the query operation includes either the shard key, *or* a prefix of
443
- the shard key, the :program:`mongos` may be able to target the query
444
- to a smaller subset of the shards. In other cases, the
445
- :program:`mongos` must query *all* shards in the cluster for
446
- results. For clusters with a small number of shards, non-targeted
447
- queries may perform acceptabily, but with more shards these
448
- non-targeted queries, are inefficient and not pratical for routine
449
- operations. When choosing a shard key, always pick a key that allows
450
- you to minimize or eleminate non-targeted queries .
451
-
452
- For more information on read operations in sharded systems , consider
436
+ :program:`mongos` uses the :term:`shard key` to determine which
437
+ :term:`shard` or shards contains the documents that could match the
438
+ query . Then, the :program:`mongos` directs the query to the relevant
439
+ shards and merges the results .
440
+
441
+ Choosing the appropriate shard key can improve the performance of the
442
+ query. If the query operation includes either the shard key, *or* a
443
+ prefix of the shard key, the :program:`mongos` may be able to target
444
+ the query to a smaller subset of the shards. Otherwise, the
445
+ :program:`mongos` performs non-targeted queries; i.e., :program:`mongos`
446
+ must query *all* shards in the cluster for the results. For clusters
447
+ with a small number of shards, the performance of non-targeted queries
448
+ may be acceptable. But, with more shards, non-targeted queries become
449
+ inefficient and impractical for routine operations .
450
+
451
+ For more information on read operations in sharded clusters , consider
453
452
the following resources:
454
453
455
454
- :ref:`An Introduction to Shard Keys <sharding-shard-key>`
0 commit comments