问题
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?
回答1:
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-
来源:https://stackoverflow.com/questions/29935665/mongodb-3-0-java-insertone