MongoDB:15-MongoDB- $isolate

  •  $isolate操作符可以对多个文档的修改提供隔离性。

  
  
  1. 针对其他线程的并发写操作,$isolate保证了提交前其他线程无法修改对应的文档。
  2. 针对其他线程的读操作,$isolate保证了其他线程读取不到未提交的数据。
   
   
  1. 官网解释:
  2. Prevents a write operation that affects multiple documents
  3. from yielding to other reads or writes once the first document is written.
  4. By using the $isolated option, you can ensure that
  5. no client sees the changes until the operation completes or errors out.

  • 但是$isolate有验证的性能问题,因为这种情况下线程持有锁的时间较长,严重的影响mongo的并发性。
  • 注意:
         
         
    1. The $isolated isolation operator
    2. does not provide all-or-nothing atomicity for write operations.
    3. 【另外,$isolate也无法保证多个文档修改的一致性(all-or-nothing),
    4. $isolate失败是可能只修改了部分文档。】
               
               
      1. $isolated 没有事件回滚机制,即时在操作过程中报错,已经修改的不会出现回滚.


    5. $isolated does not work with sharded(分片) clusters.

  • 例如:
        
        
    1. db.user.update(
    2. { _id : 1.0 , $isolated : 1 },
    3. { $inc : { age : 2 } },
    4. { multi: true }
    5. )
         
         
    1. Without the $isolated operator,
    2. the multi-update operation will allow other operations
    3. to interleave with its update of the matched documents.
    4. $atomic:Deprecated since version 2.2: The $isolated operator replaces $atomic.

参考来源:https://docs.mongodb.com/manual/reference/operator/update/isolated/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琦彦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值