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

304
Vistas
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 Respuestas
Responde la pregunta

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 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