From 5bdd836cd0c5196722689f8f7cc8cf8c687b69dc Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 12 Mar 2022 12:18:45 -0500 Subject: [PATCH] fix(connection): avoid setting MongoClient on useDb() connections until after setting on base connection Fix #11445 --- lib/connection.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index e643e1df4e1..a73be3270a6 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -788,10 +788,6 @@ Connection.prototype.openUri = function(uri, options, callback) { } _this.client = client; - for (const db of this.otherDbs) { - _setClient(db, client, {}, db.name); - } - client.setMaxListeners(0); client.connect((error) => { if (error) { @@ -800,6 +796,10 @@ Connection.prototype.openUri = function(uri, options, callback) { _setClient(_this, client, options, dbName); + for (const db of this.otherDbs) { + _setClient(db, client, {}, db.name); + } + resolve(_this); }); });