Mongodb4.0 transaction WriteConflict write conflict problem

configure

  1. use three sets of mongo4.0 replica sets
  2. enable data modification and commit using transactions
  3. concurrent modifications to the same document exist

Code Logic

  1. Open the first transaction trans1 = mongSession1.startTransaction ()
  2. trans1.update ({aVera}, {"$inc": {"num": 1}})
  3. Open the second transaction trans2 = mongSession2.startTransaction ()
  4. trans2.update ({aVera}, {"$inc": {"num": 1}}), when a WriteConflict write conflict occurs

if the sess1 is commit or abort after 1 br 2, there will be no problem
because it is a concurrent modification operation, the one who creates the transaction first must end first
how to solve this problem. Does
have anything to do with readConcern and writeConcern? I can"t set all kinds of settings. I"ve tried it all.

Feb.16,2022

ask for the answer, has the landlord solved it?


Hello, have you solved the problem


@ panshir @ mmfly01 @ dtboy1995 have you solved your problem?

I find that there does seem to be this problem, and if your update is not a field, will there be write conflicts? For example,
trans1 = mongSession1.startTransaction ()
trans1.update ({trans1.update a}, {"$inc": {"num": 1}})
trans2 = mongSession2.startTransaction ()
trans2.update ({aVera}, {"$inc": {"NAME_222": "DDD"}}),
have you tried this

?

you can take a look at this: https://codeshelper.com/a/1190000022518374

"
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea3a0d-1c6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea3a0d-1c6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?