javascript - 无法迭代 mongodb 集合
问题描述
我正在尝试使用 Pug 遍历 MongoDb 集合。
Console.log 显示收集项。Put 遍历列表但不显示任何数据。
蒙戈模式:
mongoose.Schema({
name: String,
email: String,
});
控制器:
exports.listDB = (req, res) => {
Db.find({}, (err, users) => {
if (err) throw err;
console.log(users); // this shows the collection with id, name, email
res.render('dblist', { title: 'Database List', db_list: users });
});
};
在帕格:
extends layout
block content
h1 List Database Records
p.lead This page will show all the records in the database
hr
ul
each user, index in db_list
li= db_list.name
输出显示两行带点,但没有数据。
解决方案
在您的哈巴狗视图的每个循环中,您应该将“db_list”替换为“用户”。所以应该是:
each user, index in db_list
li= user.name
推荐阅读
- mysql - 通过过滤状态查找最新的行
- javascript - Make height responsive according to width in JavaScript
- keycloak - 基于子域切换 Keycloak Realm
- cordova - 未定义的属性'then'
- raspberry-pi3 - 具有多个 CAN 总线的 RaspberryPi 3b+ (MPC2515))
- python - MacOS:ModuleNotFoundError:没有名为“object_detection”的模块
- identityserver4 - 注销重定向 Uri 在 Google 上的操作?
- tensorflow - CNN准确率没有提高
- c# - 当我想在设置一个 coockie 后重定向时,它说 HTTP 错误 401.0 - 未经授权
- javascript - RNLocation 包问题:subscribeToLocationUpdates 有时永远不会触发,有时它会自动开始工作