Categories
JavaScript Answers

How to fix Mongoose Schema hasn’t been registered for model error with JavaScript?

Spread the love

To fix Mongoose Schema hasn’t been registered for model error with JavaScript, we require all the model files.

For instance, we write

const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/news");
require("./models/Posts");
require("./models/Comments");

to call require to require the Post and Comments schema files to register them.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *