本文介绍了如何填充猫鼬中的对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下数据
"student" : [
ObjectId("58500ea5ef914125073b040f"),
ObjectId("58500ea5ef914125073b042e")
],
我的模特,
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.
推荐答案
从我的数据中可以看到,student
是学生的array
,因此您只需在student >查询.
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.
这应该对您有用:
Classroom.findById(id).populate('student').exec(function(err,result){
...
});
这篇关于如何填充猫鼬中的对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!