🤖 Merge PR #45356 [@types/mongoose]: add Connection.useDb options by @borfig

* [@types/mongoose]: add Connection.useDb options

* [@types/mongoose]: test Connection.useDb options
This commit is contained in:
Boris Figovsky 2020-06-11 07:07:38 +03:00 committed by GitHub
parent 3c7530474e
commit 8d6b195647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -542,6 +542,12 @@ declare module "mongoose" {
getIndexes(): any;
}
interface ConnectionUseDbOptions {
/**
* If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object.
*/
useCache?: boolean;
}
/*
* section drivers/node-mongodb-native/connection.js
* http://mongoosejs.com/docs/api.html#drivers-node-mongodb-native-connection-js
@ -550,9 +556,10 @@ declare module "mongoose" {
/**
* Switches to a different database using the same connection pool.
* @param name The database name
* @param options Additional options
* @returns New Connection Object
*/
useDb(name: string): Connection;
useDb(name: string, options?: ConnectionUseDbOptions): Connection;
startSession(options?: mongodb.SessionOptions, cb?: (err: any, session: mongodb.ClientSession) => void): Promise<mongodb.ClientSession>;

View File

@ -174,6 +174,9 @@ conn1.name.toLowerCase()
conn1.host.toLowerCase()
conn1.port.toFixed()
conn1.useDb('myDb').useDb('');
conn1.useDb('myDb').useDb('', {});
conn1.useDb('myDb').useDb('', {useCache: false});
conn1.useDb('myDb').useDb('', {useCache: true});
mongoose.Connection.STATES.hasOwnProperty('');
mongoose.Connection.STATES.disconnected === 0;
mongoose.Connection.STATES.connected === 1;