首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >猫鼬有多深2级以上?

猫鼬有多深2级以上?
EN

Stack Overflow用户
提问于 2015-09-19 02:30:00
回答 1查看 745关注 0票数 0

我将评论模式定义为:

代码语言:javascript
复制
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'}]
});

当我将人口用作:

代码语言:javascript
复制
Comment.find({targetBlog: blog._id}).populate({path: 'childrenComment'}).exec(function(err, comments) {
    console.log(comments);
    res.render('blog', { blog: blog, comments: comments});
});

我发现猫鼬只有一层深。那么,我如何才能使它填充多个级别,因为级别可以是2或3或更多。

EN

回答 1

Stack Overflow用户

发布于 2015-09-19 02:42:30

您可以在填充时手动指定模型。

代码语言:javascript
复制
Comment.find({targetBlog: blog._id})
    .populate({path: 'childrenComment', model: 'Comment'})
        .exec(function(err, comments) {
            console.log(comments);
            res.render('blog', { blog: blog, comments: comments});
});

更新:

看起来,您的代码在不添加模型的情况下工作。所以问题应该在别的地方,而不是在人口方面。这就是你想要做的,对吧?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32663530

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档