Created
August 21, 2014 16:25
-
-
Save LukeChannings/24af062e726e411c5117 to your computer and use it in GitHub Desktop.
convertMongoURIToMongoClient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertMongoURIToMongoClient(u) { | |
u = u.replace('mongodb://','') | |
var a = u.split('/') | |
, b = (a.length && a[0].split('@')) | |
, c = (b.length && b[0].split(':')) | |
, d = (b.length === 2 && b[1].split(',')) | |
return d.map(function(_d) { | |
var d = _d.split(':') | |
return (function(o,s) { | |
for ( var p in o ) { | |
if ( o[p] ) s += '--'+p+' '+o[p]+' ' | |
} | |
return 'mongo ' + s + (a.length >= 2 ? a[1] : '') | |
})({ | |
host: (d.length && d[0]), | |
port: (d.length === 2 && d[1]), | |
username: (c.length && c[0]), | |
password: (c.length === 2 && c[1]) | |
},'') | |
}).join('\n') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment