replaceOne and index

i read from the mongodb manual: “If a write operation modifies an indexed field, MongoDB updates all indexes that have the modified field as a key.”. however, is a replaceOne always considered to be a modification on the indexed field? even though the replacement actually did not change the indexed field?

Hi @Wei_Sun,

“Before” and “after” docs are compared to determine if index changes are necessary. This is true for every write operations. So indexes are only updated if necessary.

Cheers,
Maxime.