Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-44441

aggregation framework should have a $find expression

    • Query Optimization

      Aggregation framework has a filter, which filters an array (and returns an array).

      I wish there was an equivalent to do a javascript Array.find(), where the filter would return the first match inside of the array

      db.test.insert({people: [{name: 'bob', value: 1}, {name: 'fred', value: 2}]});
      
      db.test.aggregate([{$addFields: {
        person: {
          $find: {
            input: '$people',
            cond: {$eq: ['$$this.name', 'fred']}
          }
        },
        people: '$$REMOVE'
      }}]);
      
      ##returns
      {person: {name: 'fred', value: 2}}

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            ben@ethika.com Ben Rotz
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: