如何通过猫鼬中的对象数组填充

How to populate through array of objects in mongoose

我有如下数据

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

],

我的模型,

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

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

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

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

根据我在您的数据中看到的,student 是学生的 array,因此您只需在 populate 查询中写入 student

这应该适合你:

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