问题描述
接着是这个问题:我有一个相关的问题.
Following on from this question: Why would this db.eval -> array.push execute twice for certain records? I have a related question.
已经指出,注释中的$isolated
实际上可以阻止MongoDB读取由多次更新引起的移动文档.
It has been stated that $isolated
, in the comments, can actually stop MongoDB from reading moved documents caused by a multi-update.
我的主要争论点是$isolated
页上的警报,其中指出: http://docs.mongodb.org/manual/reference/operator/update/isolated/#up._S_isolated
My main point of contention is the alert on the $isolated
page that states: http://docs.mongodb.org/manual/reference/operator/update/isolated/#up._S_isolated
因此,它不会首先写入内存中的静态视图,因此$isolated
只是关于停止交织操作,而不是停止从一次多次更新调用中获取已更新的文档(通过相同的操作),也就是从我看到的它没有提供所需的原子性和隔离性.
As such it doesn't first write to a static view in memory, $isolated
is merely about stopping interweaving operations not to stop getting already updated documents (by the same operation) back in a multi-update call, a.k.a from what I can see it does not provide the atomicity and isolation required.
那么$isolated
如何在这里解决相关的OP问题?
So how can $isolated
work here to solve the related OPs problem?
推荐答案
$isolated
取得写锁,直到写操作完成或遇到错误,并且在处理时不会产生该锁.这样可以防止其他读写操作.它不会提供全有或全无的原子性,因为如果在第32756个文档上发生错误,则将保留以前的32755更新.没有回滚;更新不是原子的.此更新是隔离的.
$isolated
takes a write lock until the write completes or encounters an error, and it does not yield the lock while processing. This prevents other reads and writes. It does not provide all-or-nothing atomicity because, if an error occurs on the 32756th document, the previous 32755 updates will remain. There is no rollback; the update is not atomic. The update is isolated.
但是,这对OP没有帮助,因为它是他自己的更新,正在移动文档(通过$push
)并导致它们被击中两次.在索引字段上使用排序;你总是有_id
.
This will not help the OP, however, since it's his own update that is moving documents (via $push
) and causing them to be hit twice. Use a sort on an indexed field; you always have _id
.
这篇关于$ isolated是否可以在多次更新中停止以自然顺序读取更改的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!