In Mongo any way to do check and setting like atomic operation?

Yes, that's the classic use case for MongoDB's findAndModify command.

Specifically for pymongo: find_and_modify.


All updates are atomic operations over a document. Now find_and_modify locks that document and returns it back in the same operation. This allows you to combine a lock over the document during find and then applies the update operation.

You can find more about atomic operations: http://www.mongodb.org/display/DOCS/Atomic+Operations

Best,

Norberto