我将评论模式定义为:
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或更多。
发布于 2015-09-19 02:42:30
您可以在填充时手动指定模型。
Comment.find({targetBlog: blog._id})
.populate({path: 'childrenComment', model: 'Comment'})
.exec(function(err, comments) {
console.log(comments);
res.render('blog', { blog: blog, comments: comments});
});更新:
看起来,您的代码在不添加模型的情况下工作。所以问题应该在别的地方,而不是在人口方面。这就是你想要做的,对吧?

https://stackoverflow.com/questions/32663530
复制相似问题