I read some articles and they tell me MongoDb has Lock/Unlock Concurrency feature itself. So for example I have 2 Java instances access to one MongoDb to read & update data, each of them does the same thing:
1. Query all the qualified data from MongoDb [read]
(using DBCursor cursor = collection.find(query))
2. Do some calculation and update/write back to MongoDb (maybe all of them or
one of them) [write]
I want to make sure all the qualified data which query from the MongoDb should be "locked" because they might be updated/changed later; if the other Java instance accesses to the same data at the same time, it will return the wrong result. So all of them must be accessed by only one instance at the same time until the update/write process is done (Step 2).
How does MongoDb handle this situation above? Does it have some features to achieve it itself automatically or I have to do it manually (using other application such as zookeeper)?