javascript - 如何将多个集合数据从mongodb渲染到node js中的页面

标签 javascript node.js mongodb express

我在将多个集合渲染到页面时遇到问题。我做了很多研究,但收到了类似“无法在 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});
});
});
});
});
 }
});

enter image description here enter image description here

最佳答案

您的查看位置有问题,无法通过路径pages/home找到它

先尝试调试一下,现在不要考虑 mongodb。但如果您想调试 mongodb 查询 - 只需登录到控制台您的 itemscitems

关于javascript - 如何将多个集合数据从mongodb渲染到node js中的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33800619/

相关文章:

javascript - 对象未定义时的最佳实践 if - else

node.js - 错误: EBUSY: resource busy or locked, rmdir

javascript - 使用 MongoDB 在 Express 中填充相关下拉框

php - 将 PHP 对象插入到 MONGODB 中

javascript - 跨浏览器捕获滚动事件的方法(或更简单的暂时禁用滚动的方法)

javascript - 建立一个测验 - 它有效,但仅限于第一个问题

javascript - Facebook Javascript API 调用 me/invitable_friends 在 cordova 上仅返回 25 个结果,但在 Web 上则不然

javascript - 出现错误 : cannot set headers after they are sent to the client

mysql - 无法访问 Docker 容器内的 SQL 数据库

mongodb - 获取给定用户每个对话的未读消息计数