1

Getting one weird issue, I'm not able to access any of my schema properties inside pre save middleware. When I mouse over on that property I'm able to see this error :

"Property createdAt does not exist on type Document"

following is my code :

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);
Pankaj
  • 571
  • 5
  • 20

0 Answers0