Skip to content

Commit b156fbe

Browse files
author
Sam Kleinman
committed
edits on cursor modifier handling.
1 parent 30c263b commit b156fbe

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

source/core/sharded-cluster-query-router.txt

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,35 @@ collection.
7878
{ zipcode: 1, u_id: 1 }
7979
{ zipcode: 1, u_id: 1, c_date: 1 }
8080

81-
How ``mongos`` Handles Query Flags
82-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83-
84-
If the result of the query is unsorted, the :program:`mongos` instance opens
85-
a result cursor that "round robins" results from all cursors on the
86-
shards.
87-
88-
.. versionChanged::2.0.5
89-
In versions prior to 2.0.5, the :program:`mongos` exhausted each cursor, one by one.
90-
91-
If the result is supposed to be sorted (i.e. the query used
92-
:method:`cursor.sort()`), the :program:`mongos` instance passes the `sort()` flag down to
93-
the targeted shards, and performs a merge sort of the results.
94-
95-
If the query used :method:`cursor.limit()`, the :program:`mongos` instance passes that limit
96-
down to the shards and then re-applies it to the complete result.
97-
98-
If the query used :method:`cursor.skip()`, the :program:`mongos` instance cannot pass it
99-
down to the shards since it cannot know in advance how much of the
100-
skip will be filled by each individual result. The :program:`mongos` instance
101-
therefore does *not* pass the `skip()` value down, but instead passes a
102-
`limit()` value of `(skip+limit)` down to the shards, and then performs
103-
the actual skip when assembling the complete result.
81+
How ``mongos`` Handles Query Modifiers
82+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83+
84+
If the result of the query is not sorted, the :program:`mongos`
85+
instance opens a result cursor that "round robins" results from all
86+
cursors on the shards.
87+
88+
.. versionchanged:: 2.0.5
89+
In versions prior to 2.0.5, the :program:`mongos` exhausted each
90+
cursor, one by one.
91+
92+
If the queries specifies sorted results using the
93+
:method:`~cursor.sort()` cursor method, the :program:`mongos` instance
94+
passes the :operator:`$orderby` option to the shards. When the
95+
:program:`mongos` receives results it performs a *merge sort* of the
96+
results.
97+
98+
If the query limits the size of the result set using the
99+
:method:`~cursor.limit()` cursor method, the :program:`mongos`
100+
instance passes that limit to the shards and then re-applies the limit
101+
to the result before returning the result to the client.
102+
103+
If the query specifies a number of records to *skip* using the
104+
:method:`~cursor.skip()` cursor method, the :program:`mongos` *cannot*
105+
pass the skip to the shards, and trims the result set when assembling
106+
the complete result. However, when used in conjunction with a
107+
:method:`~cursor.limit()`, the :program:`mongos` will pass the *limit*
108+
plus the value of the :method:`~cursor.skip()` to the shards to
109+
improve the efficiency of these operations.
104110

105111
Detect Connections to :program:`mongos` Instances
106112
-------------------------------------------------

0 commit comments

Comments
 (0)