您的位置:首页 > 数据库 > Mongodb

MongoDB操作:update()

2016-03-11 00:00 239 查看
@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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: