diff --git a/lib/authn.js b/lib/authn.js index e39af68..80be091 100644 --- a/lib/authn.js +++ b/lib/authn.js @@ -15,26 +15,18 @@ const {util: {BedrockError}} = bedrock; export async function openDatabase(options) { const config = bedrock.config.mongodb; - let opts; + const opts = { + connectOptions: {...config.connectOptions}, + writeOptions: {...config.writeOptions}, + ...options + }; + if(config.url) { - opts = { - url: config.url - }; + opts.url = config.url; } else { - // copy the config stuff related to connecting - opts = { - database: config.name, - authentication: {...config.authentication}, - // authSource should be set in connectOptions - connectOptions: {...config.connectOptions}, - writeOptions: {...config.writeOptions}, - ...options - }; - } - - // if a `url` was not specified, create one from the `config` - if(!opts.url) { opts.url = urls.create(config); + opts.database = config.name; + opts.authentication = {...config.authentication}; } // do unauthenticated connection to mongo server to check @@ -71,7 +63,6 @@ async function _connect(options) { logger.info('connecting to database: ' + urls.sanitize(options.url)); } - /* let connectOptions = {...options.connectOptions}; // socket related options used to be an object // they are now just general options in connectOptions @@ -82,10 +73,8 @@ async function _connect(options) { }; delete connectOptions.socketOptions; } - */ - // const client = await MongoClient.connect(options.url, connectOptions); - const client = await MongoClient.connect(options.url); + const client = await MongoClient.connect(options.url, connectOptions); const db = client.db(); const ping = await db.admin().ping();