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

155
Vistas
mongoose does not validate the updated part

I have created a userSchema mongoose model and here is the related part of my model :

  password: {
    type: String,
    required: [true, "Please enter a password"],
    minlength: [6, "Minimum password length is 6 characters"],
  },

but when i updated a record that is saved to database:

userSchema.statics.updated = async function (_id, field, value) {
  const user = await this.updateOne(
    { _id },

    {
      $set: { [field]: value, updatedAt: Date.now() },
    }
  );
};

the validation does not work i tried adding {runValidators:true} or creating a middleware like

userSchema.pre("updatedOne", function (next) {
  this.options.runValidators = true;
  next();
});

but none of them solved my problem. How can i handle that?

over 4 years ago · Santiago Trujillo
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