Keep track of changes

I was able to solve it with the following code:

  schema.pre("findOneAndUpdate", async function () {
    const modifiedFields = this.getUpdate().$set;
    key = Object.keys(modifiedFields);
    const docToUpdate = await this.model.findOne(this.getQuery());
    const locked_props = key;
    this.update({ $push: { locked_props: key } });
  });

Regards!

1 Like