[SERVER-82196] Make $[] operator from update operations available in find projections Created: 13/Oct/23 Updated: 07/Dec/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Jack Wearden | Assignee: | Backlog - Query Execution |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | arrays, mql | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Assigned Teams: |
Query Execution
|
||||
| Participants: | |||||
| Description |
|
The $elemMatch operator allows users to query for documents where at least 1 element matches all criteria in the query. The positional $ projection operator, when used with $elemMatch allows projecting a result array such that it only contains the first element that matches, filtering out any non-matches and subsequent matches. In situations where multiple documents may match and all are desired, the best alternatives I can find are:
Whereas in update, updating all documents that match an elemMatch filter is possible with $[] Being able to specify a regular find with a projection of $[] to return all matching elements would make this a significantly simpler operation https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/write-operations/embedded-arrays/#matching-all-array-elements |
| Comments |
| Comment by Katya Kamenieva [ 07/Dec/23 ] |
|
I'm going to backlog this request for now. I agree we need a better UX for working with arrays, but I'm not sure we should rely on legacy update language. |