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

870
Vistas
Mongoose deleteMany in pre-hook, how to access all documents that will be deleted?

I have this code:

postSchema.pre('deleteMany', async function (next: NextFunction) {
  try {
    console.log(this);
    return next(); // normal save
  } catch (error) {
    return next(error);
  }
});

console.log is giving a query object. Are documents available somewhere in the query?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

query in deletemany Located at _conditions key of this,so you can do like this in Post Model for example :

postSchema.pre('deleteMany', async function (next: NextFunction) {
  try {
   let deletedData =await Post.find(this._conditions).lean()
    console.log(deletedData );
    return next(); // normal save
  } catch (error) {
    return next(error);
  }
});

let Post= mongoose.model("Post", userSchema);
module.exports = Post
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