Javascript 无法迭代mongodb集合
我正在尝试使用Pug遍历MongoDb集合 Console.log显示集合项。Put迭代列表,但不显示任何数据 Mongo模式:Javascript 无法迭代mongodb集合,javascript,mongodb,express,pug,Javascript,Mongodb,Express,Pug,我正在尝试使用Pug遍历MongoDb集合 Console.log显示集合项。Put迭代列表,但不显示任何数据 Mongo模式: mongoose.Schema({ name: String, email: String, }); 控制器: exports.listDB = (req, res) => { Db.find({}, (err, users) => { if (err) throw err; console.log(users); // th
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”替换为“user”。因此,它应该是:
each user, index in db_list
li= user.name
@Gui代码如果答案有帮助,请接受它。谢谢:)