diff --git a/client/dbclient.cpp b/client/dbclient.cpp index b4b7fb8..6584020 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; @@ -583,7 +583,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 +709,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();