【发布时间】:2018-12-11 10:10:02
【问题描述】:
考虑包含另一个集合的 ID 数组的文档,我如何使用 mongoose 根据相关集合找到应用过滤器的文档? 我找不到我的错误
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 });
});
};
*/
});
提前致谢 安德烈亚
【问题讨论】:
-
如果您在问题中添加一些示例数据会更容易回答
-
在第 3 阶段之前你能得到结果吗?
-
输入filter、sorting、_count、req.params.page、req.param.count的值?
-
完成了我的英雄 :-)
-
能不能在console.log(installations)前加`**console.log(err)**;???
标签: mongoose mongodb-query mongoose-schema mongoose-populate