Mongodb 3.0 java insertOne

别说谁变了你拦得住时间么 提交于 2019-12-04 03:38:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!