I've a schema which has an array inside and I want to select an item but exclude some of the array elements which have a specific value.
Sample data:
{
_id: 1,
name: something,
department: management,
employees: [
0: {
_id: 1,
name: joe,
suspended: false
},
1: {
_id: 2,
name: clare,
suspended: false
},
2: {
_id: 3,
name: michelle,
suspended: true
}
]
}
I need to exclude clare and joe and all the others has suspended:false from the result. (I need to get the department and it's suspended employees inside)
Here is the code I tried but it didn't work... This code is excluding "suspended" field only. Not the array elements.
Department.findOne(
{ name:req.params.department},
{ 'employees.suspended': false }
, function(err, result){
if(err) {
console.log("ERROR");
console.log(err);
} else {
console.log("RESULT");
console.log(result);
}
})