[SERVER-10744] $avg should do integer summation with integer inputs Created: 11/Sep/13  Updated: 13/Apr/18  Resolved: 13/Apr/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Mathias Stearn Assignee: Charlie Swanson
Resolution: Duplicate Votes: 0
Labels: expression, usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-19735 Add aggregation support for experimen... Closed
Sprint: Query 2018-04-23
Participants:

 Description   

> db.avgtest.drop()
true
> db.avgtest.insert({nums: [NumberLong("18014398509481984"), NumberLong(1), NumberLong("-18014398509481984"),NumberLong(-1)]})
> db.avgtest.aggregate({$unwind:'$nums'}, {$group: {_id:1, avg:{$avg:'$nums'}}})
{ "result" : [ { "_id" : 1, "avg" : -0.25 } ], "ok" : 1 }



 Comments   
Comment by Charlie Swanson [ 13/Apr/18 ]

I think this was fixed as part of adding support for Decimal in the aggregation framework. Specifically, I think this commit fixed it. Closing this as a duplicate of SERVER-19735.

Comment by Asya Kamsky [ 07/Apr/18 ]

3.6 does this.

Result:

db.avgtest.aggregate({$unwind:'$nums'}, {$group: {_id:1, avg:{$avg:'$nums'}}})
{ "_id" : 1, "avg" : 0 }

Generated at Thu Feb 08 03:23:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.