@Override 數據庫
public boolean update(String dbName, String collectionName, ide
DBObject oldValue, DBObject newValue) { spa
DB db = null; get
DBCollection dbCollection = null; it
WriteResult result = null; io
String resultString = null; date
if(oldValue.equals(newValue)){ exception
return true; request
}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;
}