Mongodb 3.0 java insertOne

I am trying to upgrade an outdated application from Java driver 2.10.1 to 3.0.0 Thus, the insert method changes to insertOne. but DBCollection.insert() returned a result where I can check getError() . But MongoCollection.insertOne() does not return a value.

How to check operation error?

+5
source share
1 answer

You need to catch:

  • MongoWriteException - if the write failed due to another failure specific to the insert command
  • MongoWriteConcernException - if the write failed due to the inability to complete the write problem
  • MongoException - if the record failed due to another failure

more details here: http://api.mongodb.org/java/current/com/mongodb/client/MongoCollection.html#insertOne-TDocument-

+3
source

All Articles