zoukankan      html  css  js  c++  java
  • MongoDB操作:update()

    1. @Override  
    2.     public boolean update(String dbName, String collectionName,  
    3.             DBObject oldValue, DBObject newValue) {  
    4.         DB db = null;  
    5.         DBCollection dbCollection = null;  
    6.         WriteResult result = null;  
    7.         String resultString = null;  
    8.           
    9.         if(oldValue.equals(newValue)){  
    10.             return true;  
    11.         }else{  
    12.             try {  
    13.                 db = mongoClient.getDB(dbName); //获取数据库实例  
    14.                 dbCollection = db.getCollection(collectionName);    //获取数据库中指定的collection集合  
    15.                   
    16.                 result = dbCollection.update(oldValue, newValue);  
    17.                 resultString = result.getError();  
    18.                   
    19.                 return (resultString!=null) ? false : true;  
    20.             } catch (Exception e) {  
    21.                 // TODO: handle exception  
    22.                 e.printStackTrace();  
    23.             } finally{  
    24.                 if(null != db){  
    25.                     db.requestDone();   //关闭db  
    26.                     db = null;  
    27.                 }  
    28.             }  
    29.               
    30.         }  
    31.           
    32.         return false;  
    33.     }  
  • 相关阅读:
    vs2005新控件演示系列之 向导《Wizard》
    搬家、钱、欲望、环境与命运
    母版页里面查找Repeater内控件,并构造URL
    恭喜哦!我在这里排名到250了!)(*&^%$#
    sql查询语言[我是网管论坛转载的精华贴]
    WCF 3.5对HTTP编程的增强
    WCF基础知识问与答
    印第安人的灵魂——敏捷回顾
    元数据交换绑定的秘密
    “轻松掌握WCF 帮你找到入门砖”访谈实录
  • 原文地址:https://www.cnblogs.com/yedushusheng/p/4334017.html
Copyright © 2011-2022 走看看