[SERVER-24021] Shouldn't {$sum:1} inside a $group aggregation step give a "long" not "double" ? Created: 03/May/16 Updated: 03/May/16 Resolved: 03/May/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 3.0.11 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Minor - P4 |
| Reporter: | Nic Cottrell (Personal) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
In this step:
the field "f" is output as a Double, but since it's summing an integer, wouldn't a Long be more appropriate. Is there any way to cast inside the AF? |
| Comments |
| Comment by Charlie Swanson [ 03/May/16 ] | ||||||||||||||||
|
Hi niccottrell, The $sum accumulator will preserve the 'widest' type it sees:
To be more specific, the return type will be a 32-bit integer if all inputs were 32-bit integers, a 64-bit integer if all inputs were 32-bit or 64-bit integers, or a double if any input was a double. Hope this helps, | ||||||||||||||||
| Comment by Nic Cottrell (Personal) [ 03/May/16 ] | ||||||||||||||||
|
This is an artifact of how the aggregation framework handles the $sum command, surely? I don't see how it's got anything to do with the Javascript console (It's the same if I call from the Java driver). I really assumed that the $sum with an integer with keep the 32- or 64-bit Int BSON type. | ||||||||||||||||
| Comment by Ramon Fernandez Marina [ 03/May/16 ] | ||||||||||||||||
|
niccottrell, - Please note that the SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag, where your question will reach a larger audience. A question like this involving more discussion would be best posted on the mongodb-user group. Regards, |