【发布时间】:2017-04-13 15:09:08
【问题描述】:
我正在制作一个博客应用程序。两个model的comment和userProfile,comment看起来是这样的:
var commentSchema = new Schema({
userId: {type: Schema.Types.ObjectId, ref: 'userProfile'},
replyCommentId: [{type: Schema.Types.ObjectId, ref:'Comment'}],
commentDesc: String,
date: {type: String, default: Date.now()}
});
我已将回复保存为 cmets 本身,并通过存储在数组中的回复评论 ID 引用主评论。
我试图填充那些回复字段。
commentsModel.findOne({_id: commentId}).populate('replyCommentId')
.populate('replyCommentId.userProfile').exec(function (err, docs) {
cb(err, docs);
})
我可以用模型填充replyCommentId,但replycommentId 中的userProfile 没有被填充。
【问题讨论】:
标签: mongoose