gpt4 book ai didi

mongodb - Mongodb 并发 findAndModify 与增量操作

转载 作者:可可西里 更新时间:2023-11-01 10:51:51 28 4
gpt4 key购买 nike

如果两个代理在 Mongo 集群上同时运行此更新查询,最后 updateVersion 的预期值是多少?

db.Task.findAndModify(
{
query:{"updateVersion":21},
update:{$inc:{"updateVersion":1}}
}
);

如果答案是“23”,有没有办法保证读/写同步操作?

最佳答案

MongoDB 有 FAQ section关于并发操作。

在你的例子中,write conflict可能会发生,但 MongoDB 仍会尝试执行这两个命令:

A situation in which two concurrent operations, at least one of which is a write, attempt to use a resource in a way that would violate constraints imposed by a storage engine using optimistic concurrency control. MongoDB will transparently abort and retry one of the conflicting operations.

关于mongodb - Mongodb 并发 findAndModify 与增量操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39200890/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com