In MongoDB, are there penalties to replace the whole document when only the value of a specific field is changed?
Will it take longer to update the indexes, etc.?
In MongoDB, are there penalties to replace the whole document when only the value of a specific field is changed?
Will it take longer to update the indexes, etc.?
I suspect it will depend on how many fields you are changing. An update operation where you set all fields vs a replace operation will have similar performance characteristics.
However, an update of a single field vs a replace will have considerably larger overhead - in particular the replication (e.g., the oplog entry) will contain the entire document.
In regards to indexes - I don't believe there's any difference between an update and a replace - if you're interested, you can see details of the index like this:
db.collection.stats({ indexDetails: true }).indexDetails[indexName]
on that the cursor
object contains details on the number (and size) of operations on an index - running replaces and updates show the same increase when using update and replace.