0

I have the below docs collection structure. I'm able to filter the documnents with various approaches, but not able to filter the array inside the documents.

{
"_id": "",
"employee": {
    "EmployeeAttributeValues": {
        "EmployeeAttributeValue": [
            {.....
            },
            {.....
            },
            {.....
            },
            {.....
            }
        ]
    }
}

}

Kindly help me on how to filter the MemberAttributeValue array based on some condition.

Clifford
  • 88,407
  • 13
  • 85
  • 165
shree
  • 35
  • 11

2 Answers2

0

you can use $where operator for custom filtering https://docs.mongodb.com/v4.2/reference/operator/query/where/

Ali Erdem
  • 156
  • 1
  • 6
0
db.test.aggregate([
    { $match: {_id: <ID>}},
    { $unwind: '$<ARRAY>'},
    { $match: {'<ARRAY>.a': {$gt: 3}}},
    { $group: {_id: '$_id', list: {$push: '$<ARRAY>.a'}}}
])
Vishal
  • 1,232
  • 1
  • 6
  • 8