我有以下代码:
var lesson = new Lesson({
classroomId: req.params.classroomId,
name: req.body.name,
startDate: startDate1,
endDate: endDate1,
teacher: {
_id: classroom.teacher._id,
attendance: [],
},
students: [],
});
lesson.save();
当我检查后端时,教师密钥只有_id属性,并且没有保存考勤属性。我怀疑这是因为它是一个空数组。如何保存这样的空数组呢?
答案 0 :(得分:0)
可能是因为未正确定义课程架构。你尝试过设置......
mongoose.Schema({
.....
teacher: {
...
attendance: { type: Array, default: [] }
}
...
});