-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query
When filtering arrays we often need to reduce to the first element matching a condition. This is currently achievable with the following:
{$project: {
action: {$arrayElemAt: [{$filter: {
input: '$actions',
cond: {$eq: ['$$this.id', '$id']},
}}, 0]},
}}
A cleaner and more performant option would be to have a dedicated `find` operator:
{$project: {
action: {$find: {
input: '$actions',
cond: {$eq: ['$$this.id', '$id']},
}},
}}
This idea is analagous to the ECMAScript Array.prototype.find, and would compliment the '$filter', '$map', and '$reduce' operators that are already implemented.
- duplicates
-
SERVER-44441 aggregation framework should have a $find expression
- Backlog