- @Override
- public boolean update(String dbName, String collectionName,
- DBObject oldValue, DBObject newValue) {
- DB db = null;
- DBCollection dbCollection = null;
- WriteResult result = null;
- String resultString = null;
- if(oldValue.equals(newValue)){
- return true;
- }else{
- try {
- db = mongoClient.getDB(dbName); //获取数据库实例
- dbCollection = db.getCollection(collectionName); //获取数据库中指定的collection集合
- result = dbCollection.update(oldValue, newValue);
- resultString = result.getError();
- return (resultString!=null) ? false : true;
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- } finally{
- if(null != db){
- db.requestDone(); //关闭db
- db = null;
- }
- }
- }
- return false;
- }