【发布时间】:2016-03-07 02:40:40
【问题描述】:
我正在使用 node、express、mongo 开发一个项目,我正在尝试从数据库中查询我的所有主题。
我相信我的代码是正确的,但是当我在浏览器中运行应用程序时,我的 console.log 没有显示我的输出。
这是我的路线代码:
// show all topics
router.get('/', function(req, res, next) {
var db = req.db;
console.log('Loggin DB: ' + db);
Topic.find({}).exec(function(err, topics)
{
if(err)
{
return next(err)
console.log("Logging the error: " + err);
console.log('There were no topics based on your current location');
}
else
{
console.log('Whoop whoop we found topics near your location');
//renders the data on the page
res.render('index', { topic : topic } );
console.log("Logging data: " + topic);
console.log("Logging data title: " + topic.topicTitle);
}
});
});
【问题讨论】:
-
如果出现错误,
return将阻止您访问console.log -
就是没有错误
-
@GY22 "我相信我的代码是正确的" - 它不正确
-
@Dyrk,如果它不正确的话。是否可以为我指明正确的方向...
-
您在
find回调函数中返回topics,但您将topic传递给渲染函数。
标签: node.js express mongoose find