[SERVER-44957] Proposal: $find aggregation pipeline operator Created: 05/Dec/19  Updated: 06/Dec/22  Resolved: 05/Dec/19

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Pete Boere Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-44441 aggregation framework should have a $... Backlog
Assigned Teams:
Query
Participants:

 Description   

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.



 Comments   
Comment by David Storch [ 05/Dec/19 ]

Thanks for the feature request pete@duel.me! I'm closing this as a duplicate of SERVER-44441. Let us know if we missed something and you believe these two tickets are distinct.

Best,
Dave

Comment by Carl Champain (Inactive) [ 05/Dec/19 ]

Hi pete@duel.me,

Thank you for the example. We're assigning this ticket to the Query team for further investigation. Updates will be posted on this ticket as they happen.

Kind regards,
Carl

Generated at Thu Feb 08 05:07:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.