title: Mongoose Schema hasn't been registered for model
body: <p>I'm learning the mean stack and when I try to start the server using </p>
  
  <pre><code>npm start
  </code></pre>
  
  <p>I get an exception saying that:</p>
  
  <pre><code>schema hasn't been registered for model 'Post'. Use mongoose.model(name, schema)
  </code></pre>
  
  <p>here is my code inside /models/Posts.js</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  var PostSchema = new mongoose.Schema({
      title: String,
      link: String, 
      upvotes: { type: Number, default: 0 },
      comments: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }]
  });
  
  mongoose.model('Post', PostSchema);
  </code></pre>
  
  <p>as I can see the schema should be registered for the model 'Post', but what can be possibly causing the exception to be thrown?</p>
  
  <p>Thanks in advance.</p>
  
  <p><b>Edit:</b> Here's the exception error</p>
  
  <pre><code>/home/arash/Documents/projects/personal/flapper-news/node_modules/mongoose/lib/index.js:323
    throw new mongoose.Error.MissingSchemaError(name);
          ^
  MissingSchemaError: Schema hasn't been registered for model "Post".
  Use mongoose.model(name, schema)
  </code></pre>
  
  <p>and here's the app.js code with the mongoose initialization:</p>
  
  <pre><code>var mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/news');
  require('./models/Posts');
  require('./models/Comments');
  </code></pre>
  
  <p>before the line:</p>
  
  <pre><code>app.use('/', routes);
  </code></pre>