Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor openDatabase.
Browse files Browse the repository at this point in the history
mattcollier committed Dec 12, 2023
1 parent a75cb48 commit 62bbf2a
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions lib/authn.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 62bbf2a

Please sign in to comment.