我正在尝试在ejs页面中显示数据库值,但未显示。我的架构未添加到数据库,也没有在ejs页面上显示值
model.js
const addedSchema = new Schema({
AddedName: {
type:String
},
timestamp: {
type: String,
default: () => moment().format("dddd, MMMM Do YYYY, h:mm:ss a")
},
addedBy: {
type: String
}
});
module.exports = mongoose.model('added', addedSchema);
added.ejs
<% for(var i = 0; i <added. length; i++) { %>
<tr>
<td><%= i+1 %></td>
<td><%= added[i].AddedName %></td>
<td><%= added[i].timestamp %></td>
<td><%= added[i].addedBy %></td>
<td>
<div class="justify-content-md-center" style="width:250px !important">
<a href="/viewed/<%= added[i]._id %>" class="btn bg-blue-w rounded">view</a>
<a href="/deleting/<%= added[i]._id %>" class="btn bg-grey rounded">Delete</a>
</div>
</td>
</tr>
<% } %>
addedcontroller.js //添加了用户
const Data = new Added( {AddedName: 'abc',
addedBy: 'uhd'})
Data.save()
.then(doc => {
console.log(doc)
})
.catch(err => {
console.error(err)
})
router.get('/added', async (req,res) => {
const added = await Added . find();
res.render('added' , {
added
});
});
它没有插入数据库并显示Value。请帮忙吗?
数据库的未添加任何数据库架构来创建名称