Consider documents that contain an arrays of ID of another collection, how can I find documents applying a filter based on the related collection using mongoose? I can't find my error
Installation.aggregate(
[
// Stage 1
{
$lookup: {
from: "users",
localField: "_id",
foreignField: "_id",
as: "Users"
}
},
// Stage 2
{
$unwind: {
path: "$Users"
}
},
// Stage 3
{
$match:
{"Users.Email1" : "test@test.com"}
},
{
$sort: { _id: -1 }
},
{
$limit: 10
}
]
,function (err, installations) {
console.log(installations); //<<<<< Empty
/*
Installation.populate( 'Parent', '_id Email1','Company'), function(err,results) {
Installation.count(filter).exec(function (err, count) {
res.send({ success: true, results: installations, total: count });
});
};
*/
});
Thanks in advance Andrea