Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 2 additions & 9 deletions lib/drivers/node-mongodb-native/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
if (options.noListener !== true) {
this.otherDbs.push(newConn);
}
this.otherDbs.push(newConn);
newConn.otherDbs.push(this);

// push onto the relatedDbs cache, this is used when state changes
Expand Down
1 change: 0 additions & 1 deletion test/types/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ expectType<Promise<ConnectionSyncIndexesResult>>(conn.syncIndexes({ background:

expectType<Connection>(conn.useDb('test'));
expectType<Connection>(conn.useDb('test', {}));
expectType<Connection>(conn.useDb('test', { noListener: true }));
expectType<Connection>(conn.useDb('test', { useCache: true }));

expectType<Promise<string[]>>(
Expand Down
2 changes: 1 addition & 1 deletion types/connection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ declare module 'mongoose' {
transaction<ReturnType = unknown>(fn: (session: mongodb.ClientSession) => Promise<ReturnType>, options?: mongodb.TransactionOptions): Promise<ReturnType>;

/** 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;
Expand Down