开发者

How do nosql document stores handle concurrent modification of arrays?

Given a simple json document such as:

{ _id: 1234, messages: [...], otherfields: ... }

If two people open the document, and push a message onto the array, the first update will be clobbered by the second.

For types other than arrays, I'm ok with this.

In an rdbms this isn't an issue since the two messages are simply inserted into a messages table without problem. Similarly, I could put the messages into a separate collection but I feel I lose the advantage of using a document store where I can keep the message within the context of the document.

Are there solutions to specify a push operation within the store so that I don't have to clobber the array?

Specifically, I am looking at mongodb but I'd appreciate solutions from other others like couchdb.开发者_如何学C


You asked for a push operation for MongoDB. Well it is called $push. It will handle atomic updates for you. http://www.mongodb.org/display/DOCS/Updating#Updating-%24push

Can even pass an array to it as $pushAll

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜