1
-
2
1
.. _sharded-cluster-query-routing:
3
2
.. _sharding-read-operations:
4
3
@@ -15,21 +14,21 @@ mongos
15
14
:class: singlecol
16
15
17
16
MongoDB :binary:`~bin.mongos` instances route queries and write operations
18
- to :term:`shards <shard>` in a sharded cluster. :binary:`~bin. mongos` provide the
17
+ to :term:`shards <shard>` in a sharded cluster. `` mongos`` provides the
19
18
only interface to a sharded cluster from the perspective of
20
19
applications. Applications never connect or communicate directly with
21
20
the shards.
22
21
23
- The :binary:`~bin. mongos` tracks what data is on which shard by caching
22
+ The `` mongos` ` tracks what data is on which shard by caching
24
23
the metadata from the :ref:`config servers
25
- <sharded-cluster-config-server>`. The :binary:`~bin. mongos` uses the
24
+ <sharded-cluster-config-server>`. The `` mongos` ` uses the
26
25
metadata to route operations from applications and clients to the
27
- :binary:`~bin.mongod` instances. A :binary:`~bin. mongos` has no *persistent*
26
+ :binary:`~bin.mongod` instances. A `` mongos` ` has no *persistent*
28
27
state and consumes minimal system resources.
29
28
30
- The most common practice is to run :binary:`~bin. mongos` instances on the
29
+ The most common practice is to run `` mongos` ` instances on the
31
30
same systems as your application servers, but you can maintain
32
- :binary:`~bin. mongos` instances on the shards or on other dedicated
31
+ `` mongos` ` instances on the shards or on other dedicated
33
32
resources. See also :ref:`sharded-cluster-components-distribution`.
34
33
35
34
Routing And Results Process
@@ -43,51 +42,45 @@ cluster>` by:
43
42
44
43
#. Establishing a cursor on all targeted shards.
45
44
46
- The :binary:`~bin. mongos` then merges the data from each of the
45
+ The `` mongos` ` then merges the data from each of the
47
46
targeted shards and returns the result document. Certain
48
47
query modifiers, such as :ref:`sorting<sharding-mongos-sort>`,
49
- are performed on each shard before :binary:`~bin. mongos`
48
+ are performed on each shard before `` mongos` `
50
49
retrieves the results.
51
50
52
- .. versionchanged:: 3.6
53
-
54
- For :ref:`aggregation operations <aggregation-pipeline>` that
55
- run on multiple shards, if the operations do not require running on
56
- the database's :term:`primary shard`, these operations may route the
57
- results back to the :binary:`~bin.mongos` where the results are then
58
- merged.
51
+ :ref:`Aggregation operations <aggregation-pipeline>` running on multiple
52
+ shards may route results back to the :binary:`~bin.mongos` to merge results if they don't need to run on the database's :term:`primary shard`.
59
53
60
- There are two cases in which a pipeline is ineligible to run on
61
- :binary:`~bin.mongos`.
54
+ There are two cases in which a pipeline is ineligible to run on
55
+ :binary:`~bin.mongos`.
62
56
63
- The first case occurs when the merge part of the split pipeline
64
- contains a stage which *must* run on a primary shard. For instance,
65
- if ``$lookup`` requires access to an unsharded collection in the same
66
- database as the sharded collection on which the aggregation is running,
67
- the merge is obliged to run on the primary shard.
68
-
69
- The second case occurs when the merge part of the split pipeline
70
- contains a stage which may write temporary data to disk, such as
71
- ``$group``, and the client has specified ``allowDiskUse:true``. In this
72
- case, assuming that there are no other stages in the merge pipeline
73
- which require the primary shard, the merge will run on a
74
- randomly-selected shard in the set of shards targeted by the
75
- aggregation.
76
-
77
- For more information on how the work of aggregation is split among
78
- components of a sharded cluster query, use ``explain:true`` as a
79
- parameter to the :method:`~db.collection.aggregate()` call. The
80
- return will include three json objects. ``mergeType`` shows where the
81
- stage of the merge happens ("primaryShard", "anyShard", or "mongos").
82
- ``splitPipeline`` shows which operations in your pipeline have run on
83
- individual shards. ``shards`` shows the work each shard has done.
57
+ The first case occurs when the merge part of the split pipeline
58
+ contains a stage which *must* run on a primary shard. For instance,
59
+ if ``$lookup`` requires access to an unsharded collection in the same
60
+ database as the sharded collection on which the aggregation is running,
61
+ the merge is obliged to run on the primary shard.
62
+
63
+ The second case occurs when the merge part of the split pipeline
64
+ contains a stage which may write temporary data to disk, such as
65
+ ``$group``, and the client has specified ``allowDiskUse:true``. In this
66
+ case, assuming that there are no other stages in the merge pipeline
67
+ which require the primary shard, the merge runs on a
68
+ randomly-selected shard in the set of shards targeted by the aggregation.
69
+
70
+ For more information on how the work of aggregation is split among
71
+ components of a sharded cluster query, use ``explain:true`` as a
72
+ parameter to the :method:`~db.collection.aggregate()` call. The
73
+ return includes three json objects. ``mergeType`` shows where the
74
+ stage of the merge happens ("primaryShard", "anyShard", or "mongos").
75
+ ``splitPipeline`` shows which operations in your pipeline have run on
76
+ individual shards. ``shards`` shows the work each shard has done.
84
77
85
78
In some cases, when the :term:`shard key` or a prefix of the shard key
86
79
is a part of the query, the :binary:`~bin.mongos` performs a
87
80
:ref:`targeted operation<sharding-mongos-targeted>`, routing queries to
88
81
a subset of shards in the cluster.
89
82
90
- :binary:`~bin. mongos` performs a :ref:`broadcast
83
+ `` mongos` ` performs a :ref:`broadcast
91
84
operation<sharding-mongos-broadcast>` for queries that do *not* include the
92
85
:term:`shard key`, routing queries to *all* shards in the cluster. Some
93
86
queries that do include the shard key may still result in a broadcast
@@ -97,9 +90,9 @@ selectivity of the query.
97
90
See :ref:`sharding-query-isolation` for more on targeted and
98
91
broadcast operations.
99
92
100
- Starting in MongoDB 4.4, :binary:`~bin. mongos` can support :ref:`hedge
101
- reads <mongos-hedged-reads>` to minimize latencies. See :ref:`hedge
102
- reads <mongos-hedged-reads>` for more information.
93
+ `` mongos`` can support :ref:`hedged reads <mongos-hedged-reads>` to
94
+ minimize latencies. See :ref:`hedged reads <mongos-hedged-reads>` for
95
+ more information.
103
96
104
97
How ``mongos`` Handles Query Modifiers
105
98
--------------------------------------
@@ -131,7 +124,7 @@ from the shards and skips the appropriate number of documents when assembling
131
124
the complete result.
132
125
133
126
When used in conjunction with a :method:`~cursor.limit()`, the
134
- :binary:`~bin.mongos` will pass the *limit* plus the value of the
127
+ :binary:`~bin.mongos` passes the *limit* plus the value of the
135
128
:method:`~cursor.skip()` to the shards to improve the efficiency of these
136
129
operations.
137
130
@@ -366,6 +359,11 @@ fCV Compatibility
366
359
367
360
.. include:: /includes/fact-mongos-fcv.rst
368
361
362
+ Full Time Diagnostic Data Capture Requirements
363
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364
+
365
+ .. include:: /includes/fact-mongod-mongos-ftdc-thread.rst
366
+
369
367
370
368
Connection Pools
371
369
~~~~~~~~~~~~~~~~
0 commit comments