title: How to separate schemas, methods and statics in different files in Mongoose
body: <p>I'm trying to improve the file structure of my Nodejs code with Mongoose.</p>
  
  <p>I've already separated each Schemas in different files, but for some schemas the number of methods and statics are pretty large, and I'm ending up with schema files that are too big (>1500 lines).</p>
  
  <p>I wanted to separate the methods and schemas in different files and "require" them in the schema</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>var mongoose = require("mongoose");
  var Schema = mongoose.Schema;
  var UserSchema = new Schema({
    email: String,
    pwdhash: String,
  });
  
  UserSchema.methods.someMethod1 = function() {
    // Do something 1
  };
  
  UserSchema.methods.someMethod2 = function() {
    // Do something 2
  };
  
  var User = mongoose.model("User", UserSchema);
  </code></pre>
  
  <p>I wanted it to look like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>var mongoose = require("mongoose");
  var Schema = mongoose.Schema;
  var UserSchema = new Schema({
    email: String,
    pwdhash: String,
  });
  
  // Requiring methods
  require("./methods/user.js");
  
  var User = mongoose.model("User", UserSchema);
  </code></pre>
  
  <p>However, on the /methods/user.js file I can't find out how to retrieve the Schema (only the Model) from the mongoose instance to assign the methods.</p>
  
  <p>Am I missing something? Is there some better alternative for separating methods and statics?</p>