-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.2.1
-
Component/s: Aggregation Framework
-
None
-
Environment:amd64 Amazon Linux AMI 2012.09 with amd64 mongo installed from 10gen yum repository.
-
Fully Compatible
-
ALL
-
It appears that if one is using the Aggregation Framework on a collection where _id is an object with subfields, that $group will ignore anything that is a subfield of _id when specifying it's own _id. The main case where this will occur is in using the aggregation framework on a collection that is the output of a map reduce. It is possible to work around this by using a $project stage to rename the fields from _id.Z to Z for instance. However this presumably takes extra resources. There is also no error message which is likely to cause frustration to the developer or user.
For example the following two aggregations should in principle be identical with the project phase in the second being superfluous. The projection of value.I to I and value.U to U appear to be unnecessary as the problem seems specific to _id.
mongos> db.hourAggregate.aggregate( { $match : { "value.U" : 158, "_id.t" :"I"}} , {$group : {_id :
, count : {$sum: "$value.I"} }})
{
"result" : [
{
"_id" :
,
"count" : NumberLong(1615478)
}
],
"ok" : 1
}
mongos> db.hourAggregate.aggregate( { $match : { "value.U" : 158, "_id.t" :"I"}} , {$project : { Z:"$_id.Z", U:"$value.U", I : "$value.I"}} ,{$group : {_id :
, count : {$sum: "$I"} }})
{
"result" : [
{
"_id" :
,
"count" : NumberLong(541555)
},
{
"_id" :
,
"count" : NumberLong(470692)
},
{
"_id" :
,
"count" : NumberLong(603231)
}
],
"ok" : 1
See https://groups.google.com/d/topic/mongodb-user/Yw3fvn7udY4/discussion
- duplicates
-
SERVER-7491 Can't use subfields of composite _id in $group _id
- Closed