Skip to content

Instantly share code, notes, and snippets.

@LukeChannings
Created August 21, 2014 16:25
Show Gist options
  • Save LukeChannings/24af062e726e411c5117 to your computer and use it in GitHub Desktop.
Save LukeChannings/24af062e726e411c5117 to your computer and use it in GitHub Desktop.
convertMongoURIToMongoClient
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