The native ObjectId that Mongo generates is unique worldwide and can be safely used from a multi-threaded application.
the generated ObjectId can be obtained from DbObject under the key _id.
If the inserted document violates the unique index constraint, the java driver may throw an exception, depending on the value of WriteConcern:
http://api.mongodb.org/java/current/com/mongodb/WriteConcern.html
If the value is greater, a NORMAL exception will be thrown.
WriteConcern can be specified for each individual insertion (or update) method or globally using DBCollection.setWriteConcern
aav
source share