我正在创建一个blogapp。两个模型评论和USERPROFILE,评论看起来是这样的:猫鼬如何填充模型中引用的数组
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()}
});
我已保存的回覆意见本身并参考通过存储阵列replycomment ID主要的意见。
我试图填充这些回复字段。
commentsModel.findOne({_id: commentId}).populate('replyCommentId')
.populate('replyCommentId.userProfile').exec(function (err, docs) {
cb(err, docs);
})
我可以填充replyCommentId
与模型,但内replycommentId
userProfile
是没有得到填充。
它为我工作。我有你的逻辑。谢谢。我可以给你upvote,但我是堆栈溢出的新手,我正在建立我的声望。 –
那么如果你接受我的答案,你会得到2的声望;) –