`
kimmking
  • 浏览: 537735 次
  • 性别: Icon_minigender_1
  • 来自: 中华大丈夫学院
社区版块
存档分类
最新评论

mongodb java-driver 2.4版本的一个bug

阅读更多

void save方法本身没有throw exception,翻了翻,发现有个类似c++的getlasterror可用。

于是,写了个这样的代码:

public boolean save(....){
     CommandResult cr = db.getCollection(tableName).save(dbo) .getLastError();
     return cr.ok();
}

 

直接悲剧了,插于一段时间,就直接com.mongodb.MongoInternalException: DBPort.findOne failed

查了下源码:

synchronized DBObject findOne( DB db , String coll , DBObject q ){
        OutMessage msg = OutMessage.query( db._mongo , 0 , db.getName() + "." + coll , 0 , -1 , q , null );
        
        try {
            Response res = go( msg , db.getCollection( coll ) );
            if ( res.size() == 0 )
                return null;
            if ( res.size() > 1 )
                throw new MongoInternalException( "something is wrong.  size:" + res.size() );
            return res.get(0);
        }
        catch ( IOException ioe ){
            throw new MongoInternalException( "DBPort.findOne failed" , ioe );
        }
        
    }

 

IO异常了,fxk啊,还是去掉吧,不判断就不判断吧。

 

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics