mongoDB的findAndModify是否为"transaction-save"? [英] Is mongoDB's 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
命令是原子的.这意味着find
和modify
部分之间不能进行任何其他操作.此命令是专门为增加计数器/设置标志并同时读取它们而设计的.
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屋!