Skip to content

Commit

Permalink
feat(default-db): use dbName from uri if none provided
Browse files Browse the repository at this point in the history
* docs(mongo-client): correct jsdoc

* feat(mongo-client): use authentication db as default

Addresses NODE-1258
  • Loading branch information
gef756 authored and mbroadst committed Mar 5, 2018
1 parent b7bc5c3 commit 23b1938
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mongo_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ define.classMethod('close', { callback: true, promise: true });
* You can control these behaviors with the options noListener and returnNonCachedInstance.
*
* @method
* @param {string} name The name of the database we want to use.
* @param {string} dbName The name of the database we want to use.
* @param {object} [options=null] Optional settings.
* @param {boolean} [options.noListener=false] Do not make the db an event listener to the original connection.
* @param {boolean} [options.returnNonCachedInstance=false] Control if you want to return a cached instance or have a new one created
Expand All @@ -357,6 +357,11 @@ define.classMethod('close', { callback: true, promise: true });
MongoClient.prototype.db = function(dbName, options) {
options = options || {};

// Default to db from connection string if not provided
if (!dbName) {
dbName = this.s.options.dbName;
}

// Copy the options and add out internal override of the not shared flag
var finalOptions = Object.assign({}, this.s.options, options);

Expand Down

0 comments on commit 23b1938

Please sign in to comment.