2016-12-14 53 views
0

填充我有一个数据,如如下如何通过对象数组中猫鼬

"student" : [ 
ObjectId("58500ea5ef914125073b040f"), 
ObjectId("58500ea5ef914125073b042e") 

], 

我的模型,

student: [{type: Schema.ObjectId,ref: 'Student'}], 

我想这些数组中填充学生,

Classroom.findById(id).populate('student.student'){} 

它不工作,任何人都可以请建议help.Thanks。

+0

你加裁判模型的模式'学生:[{类型:Schema.Types.ObjectId,REF: '学生'}]' – styopdev

+0

是的,我做到了..... – MMR

+0

你可以显示你的模式的代码,并确保你有适当的数据来填充数据库。 – styopdev

回答

1

从我可以在你的数据看,student是学生的array,所以你需要只写studentpopulate查询。

这应该为你工作:

Classroom.findById(id).populate('student').exec(function(err,result){ 
    ... 
});