-
Type: Task
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: None
-
Component/s: manual
Documentation for the $sum aggregation operator discusses two modes:
- In a $group pipeline stage, $sum takes a single expression argument
- In a $project pipeline stage, $sum accepts either a single expression or an array of expressions
In doctrine/mongodb-odm#1678 (and a Stack Overflow thread linked therein), we see that the server accepts the following:
[{ "$group": { "_id": null, "games": { "$sum": { "$sum": [ "$wins", "$losses", "$ties" ] } } } }]
Since $sum isn't being used in a $project stage, I would not expect it to accept multiple arguments. I'm therefore wondering if the server is being lax in what it accepts, or if the documentation is missing some nuance. It would be good to ask a server engineer to chime in on this to clarify.
Comment from kay.kim:
I guess we could clarify that if your <expression> is itself a $sum expression, then, the nested $sum expression syntax can be stuff.
As an aside, I'm not sure why $sum was overloaded to be used in $project when we already had a $add operator.
- links to