2016-12-14 32 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){ 
    ... 
});