Database

[{_id:"1",favoriteColor:"red",updatedAt:123}]

Query

db.collection.aggregate([{"$match":{_id:{"$exists":false}}},{"$unionWith":{"coll":"collection","pipeline":[{"$documents":[{_id:"1",favoriteColor:"blue",updatedAt:123}]}]}},{"$merge":{"into":"collection","on":"_id","whenMatched":[{"$set":{"favoriteColor":{"$cond":{"if":{"$ne":["$favoriteColor","$$new.favoriteColor"]},"then":"$$new.favoriteColor","else":"$favoriteColor"}},"updatedAt":{"$cond":{"if":{"$ne":["$favoriteColor","$$new.favoriteColor"]},"then":"$$new.updatedAt","else":"$updatedAt"}}}}],"whenNotMatched":"insert"}}])

Result