node.js - 如何暂时禁用猫鼬预钩
问题描述
在我的猫鼬模式中,我pre
配置了一个非常有用的钩子来更新lastModified
我的模型的时间戳。
var Document = new Schema({
lastModified: {type: Date},
title: {type: String, default: '', trim: true},
...
}
Document.pre('save', function (next) {
this.lastModified = Date.now();
next();
});
但是,当我们升级到新版本时,我需要修改文档的某些字段而不更改 lastModified。
有没有办法为某个save()
调用或更好的设计停用 pre 挂钩,而不是使用 pre 进行时间戳更新?
解决方案
推荐阅读
- python - 无法理解如何在 django 模板中注入 crisp_form 标签
- java - 构建失败错误:java:USFW_UNSYNCHRONIZED_SINGLETON_FIELD_WRITES 如何修复现场错误报告的问题
- mongodb - 无法使用 MongoDB Compass 在 mongodb 中搜索特定日期
- android - 如何在标签布局中添加菜单
- python - 使用 Dash 和 Plotly、Python 快速可视化大表的方法
- jenkins - 在 Jenkins 中使用主动选择参数更新按钮
- statistics - 为什么这个随机分布的平均值为 0?
- kotlin - 使用 kotlin 协程时使用 try catch 块吞下异常
- typescript - 无法解析 Nest.js 中的模块依赖关系
- json - 在类声明中动态分配案例类