在mongodb中,單個的寫操作保持原子性是在單個的document 上。
$isolated operator
$isolated 一個寫操作多個documents 的時候可以防止和其他進程交織,一旦寫操作修改第一個文檔,直到些操作完成或者出錯,不會有一個client 看到這個改變。$isolated不能工作在 sharded clusters. $isolated 沒有事件回滾機制,即時在操作過程中報錯,已經修改的不會出現回滾.
db.foo.update( { status : "A" , $isolated : 1 }, { $inc : { count : 1 } }, { multi: true } )
如果咩有$isolated 更新多個documents的時候,會和其他操作進程的交織。
mongodb 的 $isolated 的用法官網詳見:https://docs.mongodb.com/manual/reference/operator/update/isolated/#up._S_isolated
mongodb 沒有事物 官網給出的事物是(two-phase commit ) 是利用在寫操作的過程中,單個的document 的原子性來模擬事物,覺得不怎么好用,詳見官網:https://docs.mongodb.com/manual/tutorial/perform-two-phase-commits/
