Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

532
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda