Mongoose find() 未在 console.log 中显示我的输出

Mongoose find() not show my output in console.log

我正在使用 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);
     }
});
});

您正在进入主题s

Topic.find({}).exec(function(err, topics)

然后你正在使用主题(它不存在)

res.render('index', { topic : topic } );
    console.log("Logging data: " + topic);
    console.log("Logging data title: " + topic.topicTitle);

您正在服务器端使用 console.log。这不会在浏览器的客户端显示,而是在命令 prompt/terminal 中显示 运行 node js.