-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The current implementation assumes that when running in mongos it should be merging results from the shards. While this applies to the first $group, it doesn't apply to any others.
mongos> for (var i=0; i<100;i++) db.foo.insert({_id:i, i:i%10}) mongos> db.foo.aggregate({$group:{_id:'$_id', i:{$first:'$i'}}},{$group:{_id:'$_id', i:{$avg:'$i'}}}) { "errmsg" : "exception: assertion src/mongo/db/pipeline/accumulator_avg.cpp:43", "code" : 0, "ok" : 0 }
Note that both stages in the pipeline work by themselves and should return each document unmodified. Also, the combined aggregation works when running on a single server.