-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.2.0-rc2
-
Component/s: Aggregation Framework
-
None
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Running an aggregation pipeline composed by the following $stdDevPop and $stdDevSamp does not produce the expected output.
If we have a collection where documents contain individual "age" field and we want to calculate the standard deviation ($stdDevPop) for a given selector (city) the pipeline should be the following:
db.ages.aggregate([ {$group: { ages: {$push:"$age"}, _id:"$city" }}, {$group: { _id: null, std: {$avg: "$ages"} }} ] )
but the output I'm currently getting is the following:
{
"waitedMS": NumberLong("0"),
"result": [
{
"_id": null,
"std": null
}
],
"ok": 1
}
Running the same operation but using an intermidiate collection does perform the expected result:
db.ages.aggregate([ {$group: { ages: {$push:"$age"}, _id:"$city", }}, {$out:'aaa'}] )
db.aaa.aggregate( {$project: {_id: "$_id", s: { $stdDevPop: "$ages"}}})
{
"waitedMS": NumberLong("0"),
"result": [
{
"_id": "NYC",
"s": 29.037802755871343
}
],
"ok": 1
}
Also tested with $avg with the same issue.
Seems like there is some issue with pipelined $group operations