In my models/user.js file:
var mongoose = require(\'mongoose\');
var Schema = mongoose.Schema;
var userSchema = new Schema({
(define schema
I've also experienced this error with ES6/Typescript. Even I imported the model, the error still persisted. According to docs here
MongooseError.MissingSchemaError
Thrown when you try to access a model that has not been registered yet
import { model, Schema } from 'mongoose';
import Company from './CompanyModel';
const ProjectSchema = new Schema({
company: { type: Schema.Types.ObjectId, ref: "Company" }
});
export default model('Project', ProjectSchema);
The tips was just to make sure to use the model explicitly, so changing ref:"Company" into ref:Company.modelName seemed fixed it.
I hope that helps some of you