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 Arun Singh Nov 30, -0001 2.3K views 2 answers
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

2 Answers

Anes Bagheri Latest answer

Answered on Aug 21, 2025

Continue your journey of research and practice to build impressive programming programs. Follow and start implementing useful products that support actions. Research geometry dash lite with many sources of information to accumulate and learn new knowledge.

Was this helpful?

Arun Singh JanBask Expert

Answered on Jun 22, 2021

Was this helpful?

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.