diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/stat.cpp | 12 | ||||
-rw-r--r-- | tools/tool.cpp | 4 | ||||
-rw-r--r-- | tools/tool.h | 1 |
3 files changed, 14 insertions, 3 deletions
diff --git a/tools/stat.cpp b/tools/stat.cpp index 64f2c2f48b2..b2c5447ad21 100644 --- a/tools/stat.cpp +++ b/tools/stat.cpp @@ -51,6 +51,8 @@ namespace mongo { ; addPositionArg( "sleep" , 1 ); + + _autoreconnect = true; } virtual void printExtraHelp( ostream & out ){ @@ -210,7 +212,15 @@ namespace mongo { while ( _rowCount == 0 || _rowNum < _rowCount ){ sleepsecs(_sleep); - BSONObj now = stats(); + BSONObj now; + try { + now = stats(); + } + catch ( std::exception& e ){ + cout << "can't get data: " << e.what() << endl; + continue; + } + if ( now.isEmpty() ) return -2; diff --git a/tools/tool.cpp b/tools/tool.cpp index bfc28a2f434..e6ef7bb564d 100644 --- a/tools/tool.cpp +++ b/tools/tool.cpp @@ -38,7 +38,7 @@ namespace mongo { Tool::Tool( string name , bool localDBAllowed , string defaultDB , string defaultCollection , bool usesstdout ) : _name( name ) , _db( defaultDB ) , _coll( defaultCollection ) , - _usesstdout(usesstdout), _noconnection(false), _conn(0), _paired(false) { + _usesstdout(usesstdout), _noconnection(false), _autoreconnect(false), _conn(0), _paired(false) { _options = new po::options_description( "options" ); _options->add_options() @@ -155,7 +155,7 @@ namespace mongo { // do nothing } else if ( _host.find( "," ) == string::npos ){ - DBClientConnection * c = new DBClientConnection(); + DBClientConnection * c = new DBClientConnection( _autoreconnect ); _conn = c; string errmsg; diff --git a/tools/tool.h b/tools/tool.h index 70dd0e822f8..29dee010409 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -96,6 +96,7 @@ namespace mongo { bool _usesstdout; bool _noconnection; + bool _autoreconnect; void addFieldOptions(); void needFields(); |