如何告诉猫鼬在特定时间后自动增加存储值



假设我是这样的学生模型:

const Schema = mongoose.Schema;
const StudentSchema = new Schema({
fullName: {
type: String,
required: true,
unique: true,
trim: true,
maxLength: 60,
minLength: 3,
},
studentID: {
type: String,
required: true,
unique: true,
trim: true,
maxLength: 60,
minLength: 3,
},
semester: {
type: Number,
min: 1,
max: 15,
}
});
module.exports = mongoose.model('StudentModel', StudentSchema);

如何告诉猫鼬在Express应用程序中每6个月自动将学期增加一个

这是一个可能会有所帮助的例子。添加此属性。

semester_next_time: {
type: Date,
}
StudentSchema.pre('find', function() {
// if semester_next_time is   less than now  do stuff and update next time semester
});

最新更新