我有一个SchemaDefinition用作主模式的类型,如下所示:
const originRef: SchemaDefinition = {
attendant: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true
},
...
};
const attendanceLogSchema = new Schema({
from: {
type: originRef,
required: true
},
...
});
export const AttendanceLog = model('AttendanceLog', attendanceLogSchema);
当我尝试获取文档并填充 from.attendant 属性时,它总是充满 null ,如下所示:
return AttendanceLog.find(conditions)
.populate('from.attendant')
.select('-updatedAt')
.sort({ createdAt: -1 })
.limit(pageSize)
.skip(pageNumber * pageSize)
.exec()
我做错什么了!!