Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda