exports.repo_search = function(req, res, next) {
Repo.findById(req.params.id).populate('repo').exec(function(err, repo) {
//let num = Repo.findById(req.params.id).find({ Repo_id: 2 }).exec(err, repo){
console.log(num);
if (err) {
return next(err);
}
if (repo == null) {
// No results.
var err = new Error('Repo copy not found');
err.status = 404;
return next(err);
}
Dependencies.find({ Repo_id: '3' }, { dependencies: 1, _id: 0 }).exec(function(err, list_dependencies) {
if (err) {
return next(err);
}
console.log(JSON.stringify(list_dependencies));
// Successful, so render.
//res.render('dependencies_list', { title: 'Dependencies List', list_dependencies: list_dependencies });
// Successful, so render.
res.render('repo_info_detail', {
title : 'Repo Detail',
repo : repo,
list_dependencies : list_dependencies
// repo_dependencies: results.repo_search
});
// console.log(Repo._id);
});
});
};
"_id" : ObjectId("5c7c1d1663f56d1418667744"),
"Repo_id" : "3",
"Dep_id" : 1,
"dependencies" : [
{
"name" : "async",
"version" : "2.6.1"
},
{
"name" : "body-parser@1.18.3",
"version" : "1.18.3"
},
{
"name" : "cookie-parser@~1.4.3",
"version" : "1.4.3"
},
{
"name" : "debug@~2.6.9",
"version" : "2.6.9"
},
{
"name" : "express@~4.16.0",
"version" : "4.16.4"
},
{
"name" : "http-errors@~1.6.2",
"version" : "1.6.3"
},
{
"name" : "mongoose",
"version" : "5.3.13"
},
{
"name" : "morgan@~1.9.0",
"version" : "1.9.1"
},
{
"name" : "pug@2.0.0-beta11",
"version" : "2.0.0-beta11"
}
]
}
"_id" : ObjectId("5c71375bc6c23a17ebc9161e"),
"Repo_id" : [
"2"
],
"name" : "express-ibm",
"version" : "0.0.0"
}
{
"_id" : ObjectId("5c714b04c6c23a22b3b781b6"),
"Repo_id" : [
"3"
],
"name" : "express-ibm",
"version" : "0.0.0"
}
{
"_id" : ObjectId("5c7c1d1663f56d1418667743"),
"Repo_id" : [
"3"
],
"name" : "express-ibm",
"version" : "0.0.0"
}
嗨,我正在尝试呈现一个页面。当我单击链接时,它将使用上述控制器。我正在尝试编写代码,该代码将首先从回购的集合中通过ID查找回购(这有效,它将找到回购并输出其详细信息),但是在呈现页面之前,我希望它使用选定的回购和查询使用repo_id的依赖项集合,然后将两个结果都呈现到页面上。我可以像上面我的代码中那样通过对第二个查询进行硬编码来使其工作。由于我迷失了这个问题,我们将不胜感激。在此先感谢