MongoDB Integrity Update edge case

前端 未结 1 1966
不思量自难忘°
不思量自难忘° 2021-01-22 02:20

Hello I have the following JSON in database,

{
   recordName : String
   amount : Number
   approved : Boolean
}

Lets say I have two users issu

相关标签:
1条回答
  • 2021-01-22 03:06

    Because single document updates are atomic, regardless of the order that your two commands execute, the document will end up as:

    {amount : 9999, approved: true, ...}
    

    If the first command executes first, then the second command will override it.

    If the second command executes first, then the first command has no effect as approve is now true so the update conditions won't match.

    What you're (correctly) doing is the well-established optimistic concurrency or "update if current" approach to managing concurrent access.

    0 讨论(0)
提交回复
热议问题