Mongoose Schema hasn't been registered for model

1.5K    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

Answer (1)

The program is really diverse with different models. Start researching to create attractive development programs together. Build a quick click method to unlock many favorite Pokemon characters. Get ready to conquer the pokemon clicker game.

1 Month

Interviews

Parent Categories