[DOCS-601] Clarify how $group and $sort operations utilize shards and mongos Created: 12/Oct/12  Updated: 30/Oct/23  Resolved: 08/Nov/12

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: v1.0
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 11 years, 14 weeks, 6 days ago

 Description   

The current documentation is not accurate with the aggregation framework's behavior.

When operating on a sharded collection, the aggregation pipeline is split into two parts. The aggregation framework pushes all of the operators up to and including the first $group or $sort to each shard. Then, a second pipeline on the mongos runs. This pipeline consists of the first $group or $sort and any remaining pipeline operators, and runs on the results received from the shards.

The mongos pipeline merges $sort operations from the shards. The $group operator brings in any “sub-totals” from the shards and combines them: in some cases these may be structures. For example, the $avg expression maintains a total and count for each shard; mongos combines these values and then divides.

In reality (from redbeard0531):

$sort only happens on the mongos, not on the shards. This will change in 2.4 for a $sort followed by a $limit.



 Comments   
Comment by auto [ 08/Nov/12 ]

Author:

{u'date': u'2012-11-08T18:04:22Z', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: DOCS-601: correction about sorts and the aggregation framework.
Branch: master
https://github.com/mongodb/docs/commit/316b92cfc414939a5f5574e416aa039e231912d2

Generated at Thu Feb 08 07:39:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.