title: Mongoose Sub-documents on separate files, how to embed them
body: <p>I'm defining my application models and i have separate files for each model that i'm defining, my question is, i need to create a model that use a sub-document, but that's on another file, how can i use that Schema on my model ? what i mean is that all examples i've seen declare the  Child model and the Parent on the same file, example: </p>
  
  <pre><code>var childSchema = new Schema({ name: 'string' });
  
  var parentSchema = new Schema({
    children: [childSchema]
  });
  </code></pre>
  
  <p>I have one file called <code>user.js</code> that defines the user model : </p>
  
  <pre><code>var mongoose  = require('mongoose');
  var Schema    = mongoose.Schema;
  
  var userSchema = new Schema({
  
    _id           : Schema.Types.ObjectId,
    username      : String,
  
  });
  
  
  module.exports = mongoose.model( 'User', userSchema );
  </code></pre>
  
  <p>And on another file called <code>sport.js</code> i have the other model definition for the sports:</p>
  
  <pre><code>var mongoose  = require('mongoose');
  var Schema    = mongoose.Schema;
  
  var sportSchema = new Schema({
  
    _id       : Schema.Types.ObjectId,
    name      : String
  
  });
  
  module.exports = mongoose.model( 'Sport', sportSchema );
  </code></pre>
  
  <p>So on my user model I need to define a field for the sports that the user will follow, but i do not know how to define that sub-document since the sports definition is on another file, I tried this:</p>
  
  <pre><code>var mongoose  = require('mongoose');
  var Schema    = mongoose.Schema;
  var SportsModel = require('sport');
  
  var userSchema = new Schema({
  
    _id           : Schema.Types.ObjectId,
    username      : String,
   sports         : [SportsModel]
  
  });
  
  
  module.exports = mongoose.model( 'User', userSchema );
  </code></pre>
  
  <p>But i'm not sure if that's the correct way since what i'm exporting is the model, not the Schema. </p>
  
  <p>Thanks in advance, i want to define each model on separate files to maintain order.</p>