在findOneAndUpdate()的前钩子上修改mongoose文件

我有一个mongoose模式

var schema = new Schema({ id:Number updated_at:Date }); 

我正在使用findOneAndUpdate()来更新这个模型

 model.findOneAndUpdate( { id: json.id }, json, { upsert: true, runValidators: true }) .then(() => { recordsUpdated++; }) .catch((err) => { this.emit('error', err); }); 

json中传递的值是不正确的,我需要对它进行一些修改。 我正在寻找一个pre-hook来做修改。 我努力了

 faction.pre('findOneAndUpdate', function (next) { this.update({ $set: { updated_at: this.getUpdate().updated_at * 1000 } }); next(); }); 

简而言之,我想在更新数据库之前将时间戳记(以秒为单位)转换为毫秒,但这不起作用。

盲目地把石头扔到四周后,对我来说是有效的

 schema.pre('findOneAndUpdate', function (next) { this._update.updated_at *= 1000; next(); }); 

总之,需要修改_update属性中的文档。