[SERVER-35647] $let inside $map not working properly Created: 18/Jun/18 Updated: 08/Feb/23 Resolved: 20/Jun/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 3.6.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Hegener | Assignee: | Asya Kamsky |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
Given the following document:
When I run:
I would expect to receive:
However, the result is this:
|
|||||||||||||||||||||||||||||||||||||||||
| Participants: |
| Description |
|
In v3.6.0, $let inside $map appears to get evaluated at the wrong point in time. See "Steps To Reproduce" for details.
|
| Comments |
| Comment by Asya Kamsky [ 18/Jun/18 ] | |||||||||||||||||||||||||||||||||||||||
|
I realized that there is a hard-to-see syntax error in your aggregation. The switch expression has an array called branches, each element of which is a subdocument. In your case you have a single document with two fields called "case". What happens in JS is that the second one overrides the first one and by the time the server gets the expression, it's as if the first "case:" field was not there at all. Corrected, the right result is returned:
| |||||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 18/Jun/18 ] | |||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 18/Jun/18 ] | |||||||||||||||||||||||||||||||||||||||
|
I can reproduce this without using $let so I think something else is going on.
|