Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

531
Views
Mongoose Populate - Missing Schema Error, but the schema is properly registered for the model

Last day of 2021! After spending just over 5 hours scouring the internet I've resorted to posting for help.

Desired Behaviour:

  • the list of documents returned by the route will contain populated documents instead of only the ref ids

Attempted Resolutions:

  • added exec function after populate
  • Stackoverflow lead me down a rabbit hole of believing the issue was related to mongoose connections, and so I revamped the backend so that my model files returned schemas instead of models, and then used mongoose.createConnection instead of .connect, and made a db.js module to hold a single instance of each model (connection.mode()) that route files could then access and share. I did not reach a point where I could test .populate so I git reset back to the below code

Error

MissingSchemaError: Schema hasn't been registered for model "progressions".
Use mongoose.model(name, schema)

Note that this error is thrown when trying to populate "lesson" as well

Progress Model

const Progress = mongoose.model('Progress', new Schema({
  lesson: {
    type: Schema.Types.ObjectId,
    ref: 'lesson'
  },
  progressions: [{
    type: Schema.Types.ObjectId,
    ref: 'progression'
  }],
  progress:{
    type: Number
  },
  user:{
    type: Schema.Types.ObjectId,
    ref: 'user'
  }
},{
  timestamps: true,
}));

module.exports = Progress;

Progress Routes File

router.get('/all', async (req, res) => {
  let user = await User.find({email:req.query.user})
  let data = await Progress.find({user:user}).populate('progressions')
  return res.status(201).json({
     data,
    message: 'data populated',
    success: true
  });
});

Progression Model

const Progression = mongoose.model('Progression', new Schema({

  type:{
    type:String
  },
  toBeReviewed:{
    type: Date,
    default: Date.now
  },
},{
  timestamps: true,
}));

module.exports = Progression;
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Try to change the progressions property ref attribute in the Progress schema to match the Progression model name (capitalize it):

progressions: [{
    type: Schema.Types.ObjectId,
    ref: 'Progression'
}]
over 4 years ago · Santiago Trujillo Report

0

All code in your mongoose files should have run before it is used in other files.

This error could be happening because your mongoose models aren't executed before they are used in some other file.

over 4 years ago · Santiago Trujillo Report

0

did you try using "Progressions" while passing it in populate ?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!