我在将多个集合渲染到页面时遇到问题。我做了很多研究,但收到了类似“无法在 View 目录中查找 View ”的错误 我的代码如下
router.get('/', function(req, res, next) {
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
db.collection('book', function(err, collection1) {
collection1.find().toArray(function(err, items) {
db.collection('category', function(err, collection) {
collection.find().toArray(function(err, citems) {
res.send('pages/home', {title:'Express',itm:items,citm:citems});
});
});
});
});
}
});
最佳答案
您的查看位置有问题,无法通过路径pages/home
找到它
先尝试调试一下,现在不要考虑 mongodb。但如果您想调试 mongodb 查询 - 只需登录到控制台您的 items
和 citems
关于javascript - 如何将多个集合数据从mongodb渲染到node js中的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33800619/