Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

Mongoose Schema hasn't been registered for model

Asked by Abhinayan Verma Jun 22, 2021 1.4K views 1 answer
Share

About this question

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.

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.