title: Mongoose nested schema vs nested models
body: <p>What is the difference between nesting schema in schema (subdocuments) vs creating two separate models and referring to them, What about their performance?</p>
  
  <p><strong>subdocuments:</strong> </p>
  
  <pre><code>const postSchema = new Schema({
    title: String,
    content: String
  });
  
  const userSchema = new Schema({
    name: String,
    posts: [postSchema]
  });
  
  module.export = mongoose.model('User', userSchema);
  </code></pre>
  
  <p><strong>nested models (Populating by reference):</strong> </p>
  
  <pre><code>const postSchema = new Schema({
    title: String,
    content: String,
    author: { type: String, ref: 'User' }
  });
  module.export = mongoose.model('Post', postSchema);
  
  const userSchema = new Schema({
    name: String,
    posts: [{ type: Schema.Types.ObjectId, ref: 'Post'}]
  });
  module.export = mongoose.model('User', userSchema);
  </code></pre>
  
  <p><strong>Edit:</strong> This is not a duplicate question.</p>
  
  <p>In this question: <a href="https://stackoverflow.com/questions/15208711/mongoose-subdocuments-vs-nested-schema">Mongoose subdocuments vs nested schema</a> - mongoose subdocuments and nested schema is exactly the same.
  BUT nested models creating a separate collection in database. 
  My question is what is diffrence in nested schema vs nested models, not subdocuments vs nested schema.</p>