0
中间件
让我们考虑这样的模式:更新last_edit与猫鼬和的NodeJS
var elementSchema = new Schema({
name: String,
last_edit: { type: Date, default: Date.now }
});
现在,我每次更新任何元素。 name
我希望猫鼬直接更新last_edit
时间。
var schema = new Schema(..);
schema.pre('save', function (next) {
// do stuff
next();
});
我可能会更新它,而不是// do stuff
,但要保存不通过, 任何暗示的文件?