0
我想要訪問博客模式內的主體。我該怎麼做。如何訪問節點中的數組中的對象
模式:
var ArticleSchema = new mongoose.Schema({
blog: [{
topic: { type: String, unique: false, lowercase: true },
body: { type: String, unique: false, lowercase: true },
tags: [ 'first', 'mongodb', 'express'],
created: Date,
modified: { type : Date, default : Date.now },
state: { type: String, unique: false, lowercase: true }
}]
});
**
路由器
**
router.get('/blog/article/:postid', function (req, res, next) {
Article.findById({ _id: req.params.postid }, function (err, article) {
if (err) return next(err);
res.render('main/publishedArticle', {
article: article,
message: req.flash('showing article ' + article.title)
});
});
});
**
個publishedArticle.ejs
**
<h3><%= article.blog.body %></h3>
我我越來越不確定
謝謝,看起來很簡單 – CODI