2016-12-14 55 views
0

我要填充的学生在我的数据,如何使用填充节点JS

"attendances" : [ 
    { 
     "_id" : ObjectId("5851702b9accfc6e70d55107"), 
     "students" : [ 
      { 
       "student" : ObjectId("5850e6d596d4de3c1f4a0614"), 
       "_id" : ObjectId("5851702b9accfc6e70d55109"), 
       "ispresent" : "No" 
      }, }] 

我的架构,

attendances: [{ 
date: { 
    type: String, 
    default: '' 
}, 
created_by: { 
    type: Schema.ObjectId, 
    ref: 'Employee' 
}, 
students: [{ 
    student: { 
     type: Schema.ObjectId, 
     ref: 'Student' 
    }, 
    ispresent: { 
     type: String, 
     default: '' 
    } 
}] 

}],

Attendance.findById(id).populate('attendances.students') 

我试过以上方式但失败。可以任何人请建议help.Thanks。

+0

你放下你的猫鼬的模式和编辑你从猫鼬期待什么随着人口的格式良好的JSON? –

+0

请正确格式化您的代码。 – Mat

回答

0

您可以通过点符号,而你到这两个对象阵列指在年底Schema.Types.ObjectId类型的另一个有效的架构更深的挖掘,所以要根据您提到的模式写你的人口谓语,您查询是如下:

Attendance.findById(id).populate('attendances.students.student')