问题
I have a data like follows
"student" : [
ObjectId("58500ea5ef914125073b040f"),
ObjectId("58500ea5ef914125073b042e")
],
my model,
student: [{type: Schema.ObjectId,ref: 'Student'}],
I want to populate student in these array,
Classroom.findById(id).populate('student.student'){}
It is not working,can anyone please suggest help.Thanks.
回答1:
From what i can see in your data, student
is the array
of students, so you need to just write student
in the populate
query.
this should work for you :
Classroom.findById(id).populate('student').exec(function(err,result){
...
});
来源:https://stackoverflow.com/questions/41135110/how-to-populate-through-array-of-objects-in-mongoose