diff --git a/lib/connection.js b/lib/connection.js index 5a8b2c8ca5..973f7caa11 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -1798,7 +1798,6 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) { * @param {String} name The database name * @param {Object} [options] * @param {Boolean} [options.useCache=false] If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object. - * @param {Boolean} [options.noListener=false] If true, the connection object will not make the db listen to events on the original connection. See [issue #9961](https://github.com/Automattic/mongoose/issues/9961). * @return {Connection} New Connection Object * @api public */ diff --git a/lib/drivers/node-mongodb-native/connection.js b/lib/drivers/node-mongodb-native/connection.js index e45d22b0a0..3f4be863c2 100644 --- a/lib/drivers/node-mongodb-native/connection.js +++ b/lib/drivers/node-mongodb-native/connection.js @@ -55,7 +55,6 @@ Object.setPrototypeOf(NativeConnection.prototype, MongooseConnection.prototype); * @param {String} name The database name * @param {Object} [options] * @param {Boolean} [options.useCache=false] If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object. - * @param {Boolean} [options.noListener=false] If true, the new connection object won't listen to any events on the base connection. This is better for memory usage in cases where you're calling `useDb()` for every request. * @return {Connection} New Connection Object * @api public */ @@ -107,21 +106,15 @@ NativeConnection.prototype.useDb = function(name, options) { function wireup() { newConn.client = _this.client; - const _opts = {}; - if (options.hasOwnProperty('noListener')) { - _opts.noListener = options.noListener; - } - newConn.db = _this.client.db(name, _opts); + newConn.db = _this.client.db(name); newConn._lastHeartbeatAt = _this._lastHeartbeatAt; newConn.onOpen(); } newConn.name = name; - // push onto the otherDbs stack, this is used when state changes and when heartbeat is received - if (options.noListener !== true) { - this.otherDbs.push(newConn); - } + // push onto the otherDbs stack, this is used when state changes + this.otherDbs.push(newConn); newConn.otherDbs.push(this); // push onto the relatedDbs cache, this is used when state changes diff --git a/test/types/connection.test.ts b/test/types/connection.test.ts index 1e9b792d13..d2fafa3515 100644 --- a/test/types/connection.test.ts +++ b/test/types/connection.test.ts @@ -75,7 +75,6 @@ expectType>(conn.syncIndexes({ continueOnEr expectType(conn.useDb('test')); expectType(conn.useDb('test', {})); -expectType(conn.useDb('test', { noListener: true })); expectType(conn.useDb('test', { useCache: true })); expectType>( diff --git a/types/connection.d.ts b/types/connection.d.ts index d7ee4638ed..76b36d17e6 100644 --- a/types/connection.d.ts +++ b/types/connection.d.ts @@ -273,7 +273,7 @@ declare module 'mongoose' { transaction(fn: (session: mongodb.ClientSession) => Promise, options?: mongodb.TransactionOptions): Promise; /** Switches to a different database using the same connection pool. */ - useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection; + useDb(name: string, options?: { useCache?: boolean }): Connection; /** The username specified in the URI */ readonly user: string;