var schema = new mongoose.Schema({
name: { type: String, require: true },
comments: [{
id: {type: Schema.Types.ObjectId, ref: 'Comment'},
vote: Number,
}],
creator: {type: Schema.Types.ObjectId, ref: 'User'},
我可以填充creator
,但无法填充comment
Posts
.findOne({ id: id })
.populate('creator')
.populate('comments')
.exec(function (err, post) {
});
答案 0 :(得分:2)
请尝试使用此comments.id
,如下所示
Posts
.findOne({ id: id })
.populate('creator')
.populate('comments.id')
.exec(function (err, post) {
});