summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'scripting')
-rw-r--r--scripting/sm_db.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp
index 1d0fe119511..c74baf96ba1 100644
--- a/scripting/sm_db.cpp
+++ b/scripting/sm_db.cpp
@@ -144,11 +144,13 @@ namespace mongo {
string host = "127.0.0.1";
if ( argc > 0 )
host = c.toString( argv[0] );
+
+ int numCommas = DBClientBase::countCommas( host );
shared_ptr< DBClientWithCommands > conn;
string errmsg;
- if ( host.find( "," ) == string::npos ){
+ if ( numCommas == 0 ){
DBClientConnection * c = new DBClientConnection( true );
conn.reset( c );
if ( ! c->connect( host , errmsg ) ){
@@ -157,30 +159,21 @@ namespace mongo {
}
ScriptEngine::runConnectCallback( *c );
}
- else { // paired
- int numCommas = 0;
- for ( uint i=0; i<host.size(); i++ )
- if ( host[i] == ',' )
- numCommas++;
-
- assert( numCommas > 0 );
-
- if ( numCommas == 1 ){
- DBClientPaired * c = new DBClientPaired();
- conn.reset( c );
- if ( ! c->connect( host ) ){
- JS_ReportError( cx , "couldn't connect to pair" );
+ else if ( numCommas == 1 ){ // paired
+ DBClientPaired * c = new DBClientPaired();
+ conn.reset( c );
+ if ( ! c->connect( host ) ){
+ JS_ReportError( cx , "couldn't connect to pair" );
return JS_FALSE;
- }
- }
- else if ( numCommas == 2 ){
- conn.reset( new SyncClusterConnection( host ) );
- }
- else {
- JS_ReportError( cx , "1 (paired) or 2(quorum) commas are allowed" );
- return JS_FALSE;
}
}
+ else if ( numCommas == 2 ){
+ conn.reset( new SyncClusterConnection( host ) );
+ }
+ else {
+ JS_ReportError( cx , "1 (paired) or 2(quorum) commas are allowed" );
+ return JS_FALSE;
+ }
assert( JS_SetPrivate( cx , obj , (void*)( new shared_ptr< DBClientWithCommands >( conn ) ) ) );