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

Add $filter operator to filter subdocument values

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor - P4
    • Resolution: Duplicate
    • 2.2.0
    • None
    • Querying

    Description

      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 }
             ]
            }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: