MongoDB 4.0 Transaction WriteConflict Write Conflict

  mongodb, question

Configuration

  1. Use three mongo4.0 replica sets
  2. Open to use transactions for data modification and commit
  3. There is a case of concurrent modification of the same document

Code logic

  1. Open first transactiontrans1 = mongsession1.starttransaction ()
  2. trans1.update({a:a},{“$inc”:{“num”:1}})
  3. Open the second transaction trans2 = mongsession2.starttransaction ()
  4. Trans2.update ({a: a}, {“$ inc”: {“num”: 1}}) when a WriteConflict write conflict occurs

If sess1 is committed or abort after 1 and 2, there will be no problem.
Because it is a concurrent modification operation, it is impossible to be sure that the one that created the transaction must end first.
How do you solve this kind of problem?
Does it have anything to do with readConcern and writeConcern? I can’t do all kinds of settings. local, Majority, Snapshot w:1 and so on have all been tried.

Ask for the answer, has the landlord solved it?