Prefer client.s.databaseName over client.s.options.dbName.

Fixes #9827.

The client.s.databaseName property appears to have been introduced a long
time ago (in 2014), so it seems reliable:
14fd60b99d

The use of client.s.options.dbName was only recently introduced in #9790,
since the MongoDB.connect callback now receives a MongoClient object
rather than a Db object. Not sure if client.s.options.dbName was ever
reliable, but at least we know when the problem started.
This commit is contained in:
Ben Newman
2018-04-19 10:08:45 -04:00
parent 5189713d01
commit 567e620a86

View File

@@ -177,7 +177,11 @@ MongoConnection = function (url, options) {
// Use the internal `s` object to get the database name from the
// connection URL (parsed by the driver).
var db = client.db(client.s.options.dbName);
var db = client.db(
client.s.databaseName ||
// An older way of getting the name, supported as a fallback.
client.s.options.dbName
);
// First, figure out what the current primary is, if any.
if (db.serverConfig.isMasterDoc) {