是 mongoDB 的 findAndModify "transaction-save" [英] Is mongoDB's findAndModify "transaction-save"

查看:25
本文介绍了是 mongoDB 的 findAndModify "transaction-save"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,mongo DB 上没有事务支持.但现在我需要读取一个文档的值,增加 1 并写入新值.

i know, there is no transaction support on mongo DB. But now i need to read an value of an document, increment by 1 and write the new value.

或者 - 不同的方式:更新元素并同时读取值.为此,我喜欢使用查找和修改:http://www.mongodb.org/display/DOCS/findAndModify+Command

Or - different way: Update an element and read the value at the same time. For this i like to use find and modify : http://www.mongodb.org/display/DOCS/findAndModify+Command

此命令更新文档并返回更新前的值.这是否发生在(相同的)交易中?关键是:其他会话是否有可能在另一个会话的两个步骤之间更新相同的值?

this command updates an document and returns the value before updating. Is this happens in on (same like) transaction? The point is: is it possible that an other session updates the same value between the two steps of the other session?

(对不起,对我来说这很难解释——我希望你能理解我想说的)

(sorry, for me it's hard to explain - i hope you understand what i'm trying to say)

谢谢.

推荐答案

findAndModify 命令是原子的.这意味着在 findmodify 部分之间不能发生其他操作.此命令专为诸如增加计数器/设置标志并同时读取它们之类的事情而创建.

findAndModify command is atomic. Which means that no other operation can happen between find and modify parts. This command was made exactly for things like incrementing counters/settings flags and reading them at the same time.

这篇关于是 mongoDB 的 findAndModify "transaction-save"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆