Mongodb $set Update Different Fields in Same Document, Will It Produce Dirty Data
Under high concurrency, different fields may be updated at the same time, for example, two people update at the same time, a updates field 1 and b updates field 2. Could A be updating while B is updating and then the fields updated by A go back? An article said that $set is to update a field, and this operation is atomic. However, I have not seen this description in many places or authoritative places. This problem I mentioned above will not arise, will it?
$set of mongoDB modifierby lockymeng
Perhaps the following two sentences are executed at the same time
To correct it, it has been confirmed that it is an atomic operation, but I didn’t watch it carefully, but I am still a little confused. Does updating different fields at the same time have any effect?
Mongo’s writing to a single document is always atomic.
In fact, the main topic is to want an authoritative statement, certainly there is nothing more authoritative than official documents:
In MongoDB, a write operation is atomic on the level of a single document, even if the operation modifies multiple embedded documents within a single document.
When a single write operation modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic and other operations may interleave.
In mongo, the writing of a single document is always atomic, even if multiple nested documents in a single document are updated at the same time.
When an operation updates multiple documents at the same time, the write operation of the operation to each single document is atomic, but the whole batch update operation is not atomic, and other operations may be staggered.