Skip to content

Commit 23b1938

Browse files
gef756mbroadst
authored andcommitted
feat(default-db): use dbName from uri if none provided
* docs(mongo-client): correct jsdoc * feat(mongo-client): use authentication db as default Addresses NODE-1258
1 parent b7bc5c3 commit 23b1938

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/mongo_client.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ define.classMethod('close', { callback: true, promise: true });
348348
* You can control these behaviors with the options noListener and returnNonCachedInstance.
349349
*
350350
* @method
351-
* @param {string} name The name of the database we want to use.
351+
* @param {string} dbName The name of the database we want to use.
352352
* @param {object} [options=null] Optional settings.
353353
* @param {boolean} [options.noListener=false] Do not make the db an event listener to the original connection.
354354
* @param {boolean} [options.returnNonCachedInstance=false] Control if you want to return a cached instance or have a new one created
@@ -357,6 +357,11 @@ define.classMethod('close', { callback: true, promise: true });
357357
MongoClient.prototype.db = function(dbName, options) {
358358
options = options || {};
359359

360+
// Default to db from connection string if not provided
361+
if (!dbName) {
362+
dbName = this.s.options.dbName;
363+
}
364+
360365
// Copy the options and add out internal override of the not shared flag
361366
var finalOptions = Object.assign({}, this.s.options, options);
362367

0 commit comments

Comments
 (0)