How do nosql document stores handle concurrent modification of arrays?

Question!

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.



Answers

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

By : Amala


This video can help you solving your question :)
By: admin