[SERVER-25200] $project computed fields on arrays sets every element of the array -- inconsistent with $set Created: 21/Jul/16 Updated: 06/Dec/22 Resolved: 05/Jul/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Carly Robison | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | query-44-grooming | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Query
|
||||||||||||
| Operating System: | ALL | ||||||||||||
| Steps To Reproduce: |
|
||||||||||||
| Participants: | |||||||||||||
| Description |
This behavior replaces every element of the array, when what $set does is more elegant:
However, $set errors when "a" is not an array. This behavior occurs in both the $project stage and the new $addFields stage. |
| Comments |
| Comment by David Storch [ 05/Jul/19 ] | |||||||||||
|
This ticket is suggesting a breaking change, since it would require changing the meaning of an existing projection. We do not plan on pursuing this breaking change, so I'm closing the ticket as "Won't Do". We may wish to achieve a similar effect in the future by extending the projection language to support something like {$project: {"a.$[0]": 42}}, where "$[0]" is special syntax to refer to an index of an array. | |||||||||||
| Comment by Asya Kamsky [ 25/Jul/17 ] | |||||||||||
|
To set a single field in existing array at position X is currently somewhat complex in aggregation projection, but it's not clear how common this use case is.
|