[SERVER-54687] `$pull`ed index should not override query-matched index for `$(update)` Created: 21/Feb/21 Updated: 04/Mar/21 Resolved: 03/Mar/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 4.2.12 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | TimTIM Wong | Assignee: | Edwin Zhou |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||
| Steps To Reproduce: | Run the following in a collection `testCol`.
|
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
The index of `$pull`ed element in an unrelated field becomes `$(update)` when `$set`ting another field. See steps to reproduce. Expected result is to set `{data: "Z"}` on the forth element, but it actually set it on the second element, due to pulling the second element of another unrelated field. |
| Comments |
| Comment by Edwin Zhou [ 04/Mar/21 ] | |||||||||||||||||||||
|
We agree and think that this behavior can be further clarified in our documentation. I've opened up Thanks, | |||||||||||||||||||||
| Comment by TimTIM Wong [ 03/Mar/21 ] | |||||||||||||||||||||
|
May want to clarify this in the documentation that `$` will be affected by other array operations even though `$` is not explicitly involved in those operations. | |||||||||||||||||||||
| Comment by Edwin Zhou [ 03/Mar/21 ] | |||||||||||||||||||||
|
Thank you for your report. We agree that this can be unhelpful and confusing behavior and we believe this issue duplicates SERVER-18500, which describes that multiple array matches can lead to ambiguous positional operator projections. You may find the $[<identifier>] operator helpful, where updating an element in an array can be made more explicit.
will output
Hope this helps! Best, |