Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb 3.0 java insertOne

Tags:

java

mongodb

crud

I'm trying to upgrade my legacy application from Java driver 2.10.1 into 3.0.0 So the insert method is changed into insertOne. but DBCollection.insert() returned the result, where I can check the getError(). But MongoCollection.insertOne() does not return a value.

How to check an error of operation?

like image 973
Jeff_Alieffson Avatar asked Apr 29 '15 06:04

Jeff_Alieffson


1 Answers

You have to catch:

  • MongoWriteException - if the write failed due some other failure specific to the insert command
  • MongoWriteConcernException - if the write failed due being unable to fulfil the write concern
  • MongoException - if the write failed due some other failure

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

like image 115
onof Avatar answered Oct 25 '22 20:10

onof