带有嵌入式文档的Mongoose .populate()返回null

时间:2019-02-26 17:14:42

标签: node.js mongoose mongoose-populate embedded-documents

我有一个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()

我做错什么了!!

0 个答案:

没有答案