如何在猫鼬中获取旧属性,新属性值?

时间:2019-05-30 08:57:09

标签: node.js mongodb mongoose

在对每个文档执行更新操作之后,是否有任何简单的方法来获取旧字段值?

这是我的方法:

this.model.findOne({ _id: ObjectId("5ce5475539e978110c9ac306") }, (err, res) => {
 let oldValues = res;
 this.model.update({ _id: ObjectId("5ce5475539e978110c9ac306") }, { name: "John Papa", age: 20, postal: 37024 }, { upsert: true }, (err, raw) => {
 //Log History collection
 History.model.create({ action: 'update', oldValues: oldValues, newValues: raw });
 })
  });

0 个答案:

没有答案
相关问题