title: node / mongoose: getting to request-context in mongoose middleware
body: <p>I'm using mongoose (on node) and I'm trying to add some additional fields to a model on save by using Mongoose middleware. </p>
  
  <p>I'm taking the often-used case of wanting to add a lastmodifiedsince-date. 
  However, I also want to automatically add the name/profilelink of the user which has done the save.</p>
  
  <pre><code>schema.pre('save', function (next) {
    this.lasteditby=req.user.name; //how to get to 'req'?
    this.lasteditdate = new Date();
    next()
  })
  </code></pre>
  
  <p>I'm using passport - <a href="http://passportjs.org/" rel="noreferrer">http://passportjs.org/</a> - which results in req.user being present, <code>req</code> of course being the http-request. </p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've defined <code>pre</code> on an embedded schema, while I'm calling <code>save</code> on that parent of the embedded instance. The solution posted below (passing arg as the first param of save) works on the non-embedded case, but not on mine.</p>