node.js - 如何告诉猫鼬在特定时间后自动增加存储值?
问题描述
假设我是这样的学生模型:
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
});
推荐阅读
- modelica - 变量组件的总和 - Modelica
- ios - 使用 AttributedString 立即格式化 UITextView
- python - 如果没有插入函数,我们可以使用 python 编程在数组索引中插入新元素吗?
- excel - 在矩阵上运行并查找单元格是数字还是字符串(字母)
- python - 如何在表单中找到用户名?
- python - 使用 Docker 和 GitHub Actions 在 CI/CD 管道中的何处提供必要的 Django 环境变量
- c# - Visual Studio Code 附加到用于调试 .NET Framework 的进程
- javascript - 使用自定义按钮组件将 Typeform 嵌入 React
- firebase - 我们如何解决 Flutter 应用程序中的 Firebase 函数内部异常?
- android - 如何在 Android 上使用 Retrofit 将图像上传到服务器