[SERVER-10682] Expose $multiply as both an accumulator and an expression Created: 04/Sep/13 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 2.5.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Jeremy Mikola | Assignee: | Backlog - Query Execution |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | accumulator, expression | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Assigned Teams: |
Query Execution
|
||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||
| Description |
|
This would perform like $sum, but compute the multiplied product instead of an additive sum. Just as these operators became available both as accumulators (for grouping) and expressions (for simple transformations like in $project) in 3.2, we should make $multiply work with an array of inputs, and also be available as an accumulator during the $group stage. |
| Comments |
| Comment by Charlie Swanson [ 19/Jan/18 ] | |||||||||||||||||||||||||
|
There have been several similar requests for something like this feature, so I've updated the summary and description to reflect our plans for what we would likely implement, which I think would address all the issues linked as duplicates here. | |||||||||||||||||||||||||
| Comment by Asya Kamsky [ 15/Apr/16 ] | |||||||||||||||||||||||||
|
Implementation of $reduce expression ( | |||||||||||||||||||||||||
| Comment by Jeremy Mikola [ 04/Sep/13 ] | |||||||||||||||||||||||||
|
As we discussed in the kitchen, deprecating $add and sticking with the arithmetic operator names makes sense. As for a test case, I think something based on what I wrote in
| |||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 04/Sep/13 ] | |||||||||||||||||||||||||
|
I'm suggesting we should really use $sum in both places and deprecate $add. $multiply can work in both contexts, and with arrays – no need for a sep. pipeline stage. Do you have test case for what you are interested in supporting with input and result? | |||||||||||||||||||||||||
| Comment by Jeremy Mikola [ 04/Sep/13 ] | |||||||||||||||||||||||||
|
Even if Supporting $multiply as a first-class $group operator doesn't seem correct, for the same reason that we distinguish $sum from $add. Certainly, if you wanted to compute the combined products of arrays of numbers across documents you're grouping, I suppose you could do:
| |||||||||||||||||||||||||
| Comment by Scott Hernandez (Inactive) [ 04/Sep/13 ] | |||||||||||||||||||||||||
|
Why not just make $multiple work with arrays, and in $group? |