【发布时间】:2020-03-26 14:59:22
【问题描述】:
我只能在自己的路由中将集合显示为 json 对象,但我想让集合显示在我的 index.ejs 文件下的列表中(我是 ejs 和 MongoDB 的新手) .
这是我可以在 localhost:3000/signups 中看到 json 对象的代码:
app.get("/signups", (req, res) => {
volunteer.find({}, function(err, foundData) {
if(err){
res.send('Oops, something went wrong!');
next();
}
res.json(foundData);
});
});
这是我的 index.ejs:
<body>
<h1>Hi <%= name %></h1>
<h1>Volunteers:</h1>
<!--I want to list all volunteers from the mongodb collection-->
<div id="volunteer-table"></div>
</body>
这是我在 mongo shell 中使用 db.volunteers.find().pretty() 时看到的:
[{"_id":"5dc0e9540d7f0781882910e1","firstName":"michael","lastName":"Scott","email":"ms@dunder.com","__v":0},]
【问题讨论】:
标签: javascript node.js json mongodb ejs