I am working on a project with node, express, mongo and I am trying to query all my topics out of the db.
我正在使用node,express,mongo开发一个项目,我正在尝试从db中查询我的所有主题。
I believe my code is correct but when I run the app in de browser my console.log does not show my output.
我相信我的代码是正确的,但是当我在浏览器中运行应用程序时,我的console.log不会显示我的输出。
This is my code of my route:
这是我的路线代码:
// 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);
}
});
});
2 个解决方案
#1
You are gettin topics
你是个主题
Topic.find({}).exec(function(err, topics)
And then you are using topic (it is not exists)
然后你正在使用主题(它不存在)
res.render('index', { topic : topic } );
console.log("Logging data: " + topic);
console.log("Logging data title: " + topic.topicTitle);
#2
You are using console.log on the server side. That will not be shown client side in the browser, but rather in the command prompt/terminal where you are running node js.
您正在服务器端使用console.log。这不会在浏览器中显示客户端,而是在运行节点js的命令提示符/终端中显示。
#1
You are gettin topics
你是个主题
Topic.find({}).exec(function(err, topics)
And then you are using topic (it is not exists)
然后你正在使用主题(它不存在)
res.render('index', { topic : topic } );
console.log("Logging data: " + topic);
console.log("Logging data title: " + topic.topicTitle);
#2
You are using console.log on the server side. That will not be shown client side in the browser, but rather in the command prompt/terminal where you are running node js.
您正在服务器端使用console.log。这不会在浏览器中显示客户端,而是在运行节点js的命令提示符/终端中显示。