Add limit: 1 optimization to $filter for First() and FirstOrDefault() methods with predicates
Â
- Before: { $filter: { input: '$array', as: 'x', cond: { $gt: ['$$x', 1] } } }
- After: { $filter: { input: '$array', as: 'x', cond: { $gt: ['$$x', 1] }, limit: 1 } }
Â
With limit: 1, MongoDB stops filtering after finding the first matching element instead of scanning the entire array
- related to
-
CSHARP-5789 Remove CompatibilityLevel check for $filter limit optimization in FirstOrLastMethodToAggregationExpressionTranslator
-
- Needs Triage
-