Proposal: $find aggregation pipeline operator

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Query
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Backlog - Query Team (Inactive)
            Reporter:
            Pete Boere
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: