[SERVER-10689] Add a $switch expression Created: 06/Sep/13 Updated: 19/Jul/17 Resolved: 15/Apr/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | 3.3.5 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Asya Kamsky | Assignee: | Benjamin Murphy |
| Resolution: | Done | Votes: | 7 |
| Labels: | expression, usability | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||
| Sprint: | Query 13 (04/22/16) | ||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Description |
|
Syntax
Examples
Notes
Old Description: It would be nice to have an operator to do something like:
Asya |
| Comments |
| Comment by stone [X] [ 19/May/17 ] | |||||||||
|
I used to think as you describe. BTW,will test again | |||||||||
| Comment by Asya Kamsky [ 18/May/17 ] | |||||||||
|
cnStoneFang node driver doesn't need to have any special support - $switch is an expression and as long as you are running your aggregation against server version 3.4 or later, it will work. | |||||||||
| Comment by stone [X] [ 18/May/17 ] | |||||||||
|
latest nodejs driver 2.26 still does not support $switch operation | |||||||||
| Comment by Benjamin Murphy [ 15/Apr/16 ] | |||||||||
|
This ticket introduced the $switch expression to aggregation, which must be documented and supported by drivers. | |||||||||
| Comment by Githook User [ 15/Apr/16 ] | |||||||||
|
Author: {u'username': u'benjaminmurphy', u'name': u'Benjamin Murphy', u'email': u'benjamin_murphy@me.com'}Message: | |||||||||
| Comment by John Mullanaphy [ 10/Sep/13 ] | |||||||||
|
Going to also add in a vote. Had to make an adhoc $cond to do a fake join to do sorting by name. The solution(s): One table had ids, other table had dynamically changed names associated with the ids, so had to make the aggregate query in code with $cond matching ids to names and then sorting. That had ended up hitting a hash key nesting limit, so then the next solution was to make a:
Which also hits limits if you have large numbers of names for ids. Still, switch/case isn't the solution to our problem but while trying to find solutions we realized it would have been a nice alternative to our original nested conditionals. 2.6, will need to check out the $map/$let commands. | |||||||||
| Comment by John Cole [ 06/Sep/13 ] | |||||||||
|
I'll second the need for this here. We were able to use $concat and a series of $cond to replicate a case statement but it's limited to returning strings. Adding a $case as described would greatly improve the readability of agg queries that require strict grouping parameters, a common issue in reports. |