From 567e620a867a5e34188024d3175d4cc9dedaff3b Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 19 Apr 2018 10:08:45 -0400 Subject: [PATCH] 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: https://github.com/mongodb/node-mongodb-native/commit/14fd60b99d92760e130e67e187b4c22dfd74ea7d 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. --- packages/mongo/mongo_driver.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/mongo/mongo_driver.js b/packages/mongo/mongo_driver.js index 9fae059fde..a471bb236e 100644 --- a/packages/mongo/mongo_driver.js +++ b/packages/mongo/mongo_driver.js @@ -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) {