-1
我定義的註釋模型:貓鼬如何居住在兩層以上?
CommentSchema = new mongoose.Schema ({
name: String,
email: String,
website: String,
content: String,
createDate: Date,
updateDate: Date,
targetBlog: {type: mongoose.Schema.Types.ObjectId, ref: 'Blog'},
childrenComment: [{type: mongoose.Schema.Types.ObjectId, ref: 'Comment'}]
});
當我使用的填充:
Comment.find({targetBlog: blog._id}).populate({path: 'childrenComment'}).exec(function(err, comments) {
console.log(comments);
res.render('blog', { blog: blog, comments: comments});
});
我發現貓鼬只有填充深一個層次。所以我該如何讓它填充多個等級,因爲等級可以是2或3或更多。
謝謝。但我很遺憾,它不起作用。 – user3077147
你確定'Comment.find({targetBlog:blog._id})'從數據庫中返回一個Comment嗎? – shan1024
你確定添加'model:'Comment''會幫助貓鼬填充多個層次嗎? – user3077147