2016-03-10 2 views
0
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) { 
}); 

ответ

1

Пожалуйста, попробуйте этот, с comments.id ниже

Posts 
    .findOne({ id: id }) 
    .populate('creator') 
    .populate('comments.id') 
    .exec(function (err, post) { 
    }); 
Смежные вопросы