title: How to sanitize user input in mongoose?
body: <p>I am trying to sanitize user input in mongoose. I though that using mongoose middleware would help, but it seems that I am either wrong or I am doing something wrong.</p>
  
  <p>The reason I am trying to use Mongoose middleware (and not Express middleware) is that I have a document that can have a nested document - however, that nested document can be a standalone document as well. I am trying to create a "single point of truth" for my documents so that I can sanitize only in one place.</p>
  
  <p>The following code does not seem to work:</p>
  
  <pre><code>Organization.pre("validate", function (next) {
    this.subdomain = this.trim().toLowerCase();
    next();
  });
  </code></pre>
  
  <p>PS. I am also using mongoose-validator, which in turn uses node-validator to validate the user input - node validator also has some sanitize methods, maybe I should use them somehow?</p>