Skip to content

Instantly share code, notes, and snippets.

@Itax67
Forked from imaustink/mongo-connection-url.js
Created February 23, 2024 18:52
Show Gist options
  • Select an option

  • Save Itax67/caf0cee9cd3e0536fe49c52c4e86f2c6 to your computer and use it in GitHub Desktop.

Select an option

Save Itax67/caf0cee9cd3e0536fe49c52c4e86f2c6 to your computer and use it in GitHub Desktop.
Simple Mongo DB connection URL generator in JavaScript
function mongoURL(options) {
options = options || {};
var URL = 'mongodb://';
if (options.password && options.username) URL += options.username + ':' + options.password + '@';
URL += (options.host || 'localhost') + ':';
URL += (options.port || '27017') + '/';
URL += (options.database || 'admin');
return URL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment