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.