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

Add $filter operator to filter subdocument values

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.2.0
    • Component/s: Querying

      It's something like as $elemMatch projection works but instead returning the single value it could be return all matches like the follows:

          {
           _id: ObjectId(),
           zipcode: 63109,
           dependents: [
                    { name: "john", school: 102, age: 10 },
                    { name: "jess", school: 102, age: 11 },
                    { name: "jeff", school: 108, age: 15 }
                   ]
           }
      
           var projection = { _id: 0, dependents: { $filter: { school: 102 }}};
           db.students.find( { zipcode: 63109 }, projection);
      
           {
             dependents: [
                    { name: "john", school: 102, age: 10 },
                    { name: "jess", school: 102, age: 11 }
             ]
            }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            artem Artem
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: