遇到一个奇怪的问题,我无法访问预保存中间件中的任何架构属性。当我将鼠标悬停在该属性上时,我可以看到此错误:
“文档类型上不存在属性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);