Skip to content

Commit ac9c4b5

Browse files
authored
Merge pull request #15641 from vkarpov15/codex/remove-nolistener-option-from-code
BREAKING CHANGE: remove connection `noListener` option
2 parents cbb5d10 + 7b87977 commit ac9c4b5

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

lib/connection.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,6 @@ Connection.prototype.syncIndexes = async function syncIndexes(options = {}) {
17981798
* @param {String} name The database name
17991799
* @param {Object} [options]
18001800
* @param {Boolean} [options.useCache=false] If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object.
1801-
* @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).
18021801
* @return {Connection} New Connection Object
18031802
* @api public
18041803
*/

lib/drivers/node-mongodb-native/connection.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ Object.setPrototypeOf(NativeConnection.prototype, MongooseConnection.prototype);
5555
* @param {String} name The database name
5656
* @param {Object} [options]
5757
* @param {Boolean} [options.useCache=false] If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object.
58-
* @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.
5958
* @return {Connection} New Connection Object
6059
* @api public
6160
*/
@@ -107,21 +106,15 @@ NativeConnection.prototype.useDb = function(name, options) {
107106

108107
function wireup() {
109108
newConn.client = _this.client;
110-
const _opts = {};
111-
if (options.hasOwnProperty('noListener')) {
112-
_opts.noListener = options.noListener;
113-
}
114-
newConn.db = _this.client.db(name, _opts);
109+
newConn.db = _this.client.db(name);
115110
newConn._lastHeartbeatAt = _this._lastHeartbeatAt;
116111
newConn.onOpen();
117112
}
118113

119114
newConn.name = name;
120115

121-
// push onto the otherDbs stack, this is used when state changes and when heartbeat is received
122-
if (options.noListener !== true) {
123-
this.otherDbs.push(newConn);
124-
}
116+
// push onto the otherDbs stack, this is used when state changes
117+
this.otherDbs.push(newConn);
125118
newConn.otherDbs.push(this);
126119

127120
// push onto the relatedDbs cache, this is used when state changes

test/types/connection.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ expectType<Promise<ConnectionSyncIndexesResult>>(conn.syncIndexes({ continueOnEr
7575

7676
expectType<Connection>(conn.useDb('test'));
7777
expectType<Connection>(conn.useDb('test', {}));
78-
expectType<Connection>(conn.useDb('test', { noListener: true }));
7978
expectType<Connection>(conn.useDb('test', { useCache: true }));
8079

8180
expectType<Promise<string[]>>(

types/connection.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ declare module 'mongoose' {
273273
transaction<ReturnType = unknown>(fn: (session: mongodb.ClientSession) => Promise<ReturnType>, options?: mongodb.TransactionOptions): Promise<ReturnType>;
274274

275275
/** Switches to a different database using the same connection pool. */
276-
useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
276+
useDb(name: string, options?: { useCache?: boolean }): Connection;
277277

278278
/** The username specified in the URI */
279279
readonly user: string;

0 commit comments

Comments
 (0)