I have troubles at fltering subarrays with mongoose (MongoDB driver for NodeJS).
Here's an example which I'll use to show the problem:
[
{
employee: [list of IDs], // List of employees which are in this project
entry: // Every employee can make entries
[
employee: ID //saving ID of employee
]
},
]
What I want? I want to get whole objects (of employee and entry attributes) of those in the main array. That's how I do it:
mongoose.model('team').find({
employee: "userid...", // Getting projects of an employee, but there's a missing part which I describe below.
}, function(err, teams) {
res.send(teams);
})
That's working so far. But my problem is that I don't want to list the foreign entry objects in the nested array. So I want to filter this array. I tried this with aggregate and it worked BUT my problem is that I can't get the main parent when employee doesn't have any entries. So I want to get the parent object even when employee has nothing in the nested one.
I'd be very glad when you can help me out here.
Regards