title: How to change the document using pre save in Mongoose
body: <p>I am trying to assign the pre handler to the mongoose save event and encrypt the document before saving:</p>
  
  <pre><code>userShecma.pre('save', function(next) {
      var self = {};
      self.Key = this.password;;
      self.EncriptedString = encrypt.encrypt(JSON.stringify(this), this.password);
      self.user = this.user
      self.decrypt = function() {
          var user = JSON.parse(encrypt.decrypt(this.EncriptedString, this.Key));
          for(var key in user) {
              this[key] = user[key];
          }
      }
      for(var key in this){
          delete this[key];
      }
      for(var key in self){
          this[key] = self[key];
      }
      console.log(this);
      next(self);
  });
  </code></pre>
  
  <p>I have tried a bunch of diffrent things, sometimes I get an error, sometimes it just doesnt change the document.</p>
  
  <p>Let me know if you need any more info,
  <br/> Ari</p>
  
  <p><em><strong>EDIT:</strong></em> Tried Benoir's Answer, I can't edit <code>this</code>.</p>