Mongoose Schema hasn't been registered for model

959    Asked by arun_3288 in Java , Asked on Nov 30, -0001

I'm learning the mean stack and when I try to start the server using

npm start

I get an exception saying that:

schema hasn't been registered for model 'Post'. Use mongoose.model(name, schema)

here is my code inside /models/Posts.js

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);

as I can see the schema should be registered for the model 'Post', but what can be possibly causing the exception to be thrown?

Thanks in advance.

Answered by Alison Kelly

Your Answer

Interviews

Parent Categories