MissingSchemaError: Schema hasn’t been registered for model “User”

I got the same problem when I am trying the MEAN tutorial.

After done a little bit research, I found that in app.js, if I put require(“./models/User”) before var routes = require(“./routes/index”), then it works.

Like this:


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

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

Hope the answer will be helpful!

Leave a Comment