遇到一个奇怪的问题,我无法在预保存中间件中访问我的任何架构属性。当我将鼠标悬停在该属性上时,我能够看到此错误:
“文档类型上不存在属性 createdAt”
以下是我的代码:
import * as mongoose from 'mongoose';
var StaffSchema = new mongoose.Schema({
name : {
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
middleName: {
type: String,
required: true
},
email: {
type: String,
required: true
},
signatureLine: {
type: String,
required: true
},
isActive: {
type: Boolean,
default: true
},
isWithoutSupervisorCoSign: {
type: Boolean,
default: false
},
isShowInSchedule: {
type: Boolean,
default: false
}
},
createdAt: {
type: Date
},
updatedAt: {
type: Date
}
});
StaffSchema.pre('save', function(next) {
// do stuff
this.createdAt = Date.now();
next();
});
export default mongoose.model('staff', StaffSchema);