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

309
Visualizações
Does "updating" an indexed field in mongoDB to the same value it is, will cause any change on index?

If in my code I'm updating a document in mongoDB, is it better to check if indexed fields changed and update them only if changed (there are other fields that we should update anyway), or there'll be no effect on saving indexed fields to the existing value? does mongo immediately will update the index, or if it sees that nothing actually changed it wont try to update the index?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

update operation is changing value and its index only if the value is different. example:

       PRIMARY> db.test.find()
       { "_id" : ObjectId("61eef83f6b9fd30eb14ad43b"), "test" : 1 }
       PRIMARY> db.test.update({test:1},{$set:{test:1}})
       WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })

As you can see nModified: 0 and in the oplog nothing appear meaning that the operation do not have any effect ...

If the value is different it will be updated imeediately also in the index ...

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