diff --git a/client/dbclient.cpp b/client/dbclient.cpp index b4b7fb8..aac577f 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -391,7 +391,7 @@ namespace mongo { string ns = db + ".system.namespaces"; auto_ptr c = query( ns.c_str() , BSONObj() ); - while ( c->more() ){ + while ( c.get() && c->more() ){ string name = c->next()["name"].valuestr(); if ( name.find( "$" ) != string::npos ) continue; @@ -484,6 +484,8 @@ namespace mongo { BSONObj DBClientInterface::findOne(const string &ns, Query query, const BSONObj *fieldsToReturn, int queryOptions) { auto_ptr c = this->query(ns, query, 1, 0, fieldsToReturn, queryOptions); + if ( c.get() ) + return BSONObj(); uassert( 10276 , "DBClientBase::findOne: transport error", c.get() ); @@ -583,7 +585,7 @@ namespace mongo { auto_ptr c( this->query(ns, query, 0, 0, fieldsToReturn, (int) QueryOption_Exhaust) ); - while( 1 ) { + while( c.get() ) { while( c->moreInCurrentBatch() ) { BSONObj o = c->nextSafe(); f(o); @@ -709,7 +711,7 @@ namespace mongo { void DBClientWithCommands::reIndex( const string& ns ){ list all; auto_ptr i = getIndexes( ns ); - while ( i->more() ){ + while ( i.get() && i->more() ){ all.push_back( i->next().getOwned() ); } diff --git a/client/gridfs.cpp b/client/gridfs.cpp index b2ae478..a648363 100644 --- a/client/gridfs.cpp +++ b/client/gridfs.cpp @@ -163,7 +163,7 @@ namespace mongo { void GridFS::removeFile( const string& fileName ){ auto_ptr files = _client.query( _filesNS , BSON( "filename" << fileName ) ); - while (files->more()){ + while (files.get() && files->more()){ BSONObj file = files->next(); BSONElement id = file["_id"]; _client.remove( _filesNS.c_str() , BSON( "_id" << id ) ); diff --git a/client/parallel.cpp b/client/parallel.cpp index c39ecab..e86633b 100644 --- a/client/parallel.cpp +++ b/client/parallel.cpp @@ -66,6 +66,9 @@ namespace mongo { auto_ptr cursor = conn->query( _ns , q , num , 0 , ( _fields.isEmpty() ? 0 : &_fields ) , _options ); + if ( !cursor.get() ) { + return cursor; + } if ( cursor->hasResultFlag( QueryResult::ResultFlag_ShardConfigStale ) ){ conn.done(); diff --git a/client/syncclusterconnection.cpp b/client/syncclusterconnection.cpp index 6524363..9a861d7 100644 --- a/client/syncclusterconnection.cpp +++ b/client/syncclusterconnection.cpp @@ -200,7 +200,7 @@ namespace mongo { bool SyncClusterConnection::_commandOnActive(const string &dbname, const BSONObj& cmd, BSONObj &info, int options ){ auto_ptr cursor = _queryOnActive( dbname + ".$cmd" , cmd , 1 , 0 , 0 , options , 0 ); - if ( cursor->more() ) + if ( cursor.get() && cursor->more() ) info = cursor->next().copy(); else info = BSONObj(); diff --git a/db/db.cpp b/db/db.cpp index f9d267e..adad364 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -457,7 +457,7 @@ sendmore: vector< string > toDelete; DBDirectClient cli; auto_ptr< DBClientCursor > c = cli.query( "local.system.namespaces", Query( fromjson( "{name:/^local.temp./}" ) ) ); - while( c->more() ) { + while( c.get() && c->more() ) { BSONObj o = c->next(); toDelete.push_back( o.getStringField( "name" ) ); } diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 2654084..3a798da 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -772,7 +772,7 @@ namespace mongo { list all; auto_ptr i = db.getIndexes( toDeleteNs ); BSONObjBuilder b; - while ( i->more() ){ + while ( i.get() && i->more() ){ BSONObj o = i->next().getOwned(); b.append( BSONObjBuilder::numStr( all.size() ) , o ); all.push_back( o );