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

343
Vistas
Why did the data get deleted when the condition did not match in the query

I have this schema in my mongo db.

const movieSchema = new mongoose.Schema({
    title: String,
    year: Number,
    score: Number,
    rating: String
})

When I tried to delete collections with year greater than 1999, I have mistakenly put the condition as:

 Movie.deleteMany({yeaer: {$gte: 1999}}).then(res => {console.log(res)})

This happened This happened

And all of my data got deleted Before and after deletion

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you omit the conditional property from deleteMany(), mongoose will delete all documents from the model. The same is true if you misspell the conditional. It's a rather dangerous default behaviour but you can guard yourself by disabling strict querying mode in mongoose:

mongoose.set('strictQuery', false)
about 4 years ago · Juan Pablo Isaza 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