Does MongoDB skip index updates if a field is set to its current value?

Yes, I think it is detected in all these cases. MongoDB applies the updates to generate a new version of the document, in memory, and compares it to the previous one, so it doesn’t depend on the operations, but on the state (same datatype, same values).

The best is to test, for example in a lab with db.setLogLevel(1, "write") and look at "keysInserted","keysDeleted","nModified" in the log. It’s a great question, I’ll write a blog post to explain.

1 Like