$currentDate option to only update if the document was modified
A common pattern in a data model is to have a field that denotes when the data was last modified. For this example, let this field be called "updated". I want to toggle a field on a document called "enabled", and if the value is modified I also want to update the "updated" field.
This behavior is possible right now via a comment shown in SERVER-42084, but ONLY if we include the entire document, which is not acceptable when you only want to modify a single field. This document could have other fields that are numeric and are updated atomically, and including the entire document in an "$set" update would give unexpected results. You could modify your query filter with what you expected the field to be, e.g. {_id: ..., enabled: false}
but this now makes it impossible to easily discern whether or not the document does exist, but doesn't match the filter, making you have to do another query afterwards if you want to display either "Document not found" or "Document is already enabled".
Here is an example of what I would like to do in code:
db.test.updateOne({ _id: ... }, {
$set: { enabled: true },
$currentDateIfModified: { update: true }
})