title: Using Mongoose `pre` hook to get document before findOneAndUpdate()
body: <p>I am trying to use Mongoose <code>pre</code> and <code>post</code> hooks in my MongoDB backend in order to compare the document in its pre and post-saved states, in order to trigger some other events depending on what's changed. So far however I'm having trouble getting the document via the Mongoose <code>pre</code> hook. </p>
  
  <p>According to the docs "pre hooks work for both doc.save() and doc.update(). In both cases this refers to the document itself... ". So I here's what I tried. First in my model/schema I have the following code:</p>
  
  <pre><code>let Schema = mongoose
    .Schema(CustomerSchema, {
      timestamps: true
    })
    .pre("findOneAndUpdate", function(next) {
      trigger.preSave(next);
    })
    // other hooks
  }
  </code></pre>
  
  <p>... And then in my triggers file I have the following code:</p>
  
  <pre><code>exports.preSave = function(next) {
    console.log("this: ", this);
    }
  };
  </code></pre>
  
  <p>But this is what logs to the console:</p>
  
  <blockquote>
    <p>this:  { preSave: [Function], postSave: [AsyncFunction] }</p>
  </blockquote>
  
  <p>So clearly this didn't work. This didn't log out the document as I was hoping for. Why is <code>this</code> not the document itself here, as the docs themselves appear to indicate? And is there a way I can get a hold of the document with a <code>pre</code> hook? If not, is there another approach people have used to accomplish this?</p>