@@ -203,7 +203,6 @@ export type WithSessionCallback = (session: ClientSession) => Promise<any> | voi
203
203
export interface MongoClientPrivate {
204
204
url : string ;
205
205
options ?: MongoClientOptions ;
206
- dbCache : Map < string , Db > ;
207
206
sessions : Set < ClientSession > ;
208
207
readConcern ?: ReadConcern ;
209
208
writeConcern ?: WriteConcern ;
@@ -283,7 +282,6 @@ export class MongoClient extends EventEmitter {
283
282
this . s = {
284
283
url,
285
284
options : options ?? { } ,
286
- dbCache : new Map ( ) ,
287
285
sessions : new Set ( ) ,
288
286
readConcern : ReadConcern . fromOptions ( options ) ,
289
287
writeConcern : WriteConcern . fromOptions ( options ) ,
@@ -380,15 +378,13 @@ export class MongoClient extends EventEmitter {
380
378
381
379
/**
382
380
* Create a new Db instance sharing the current socket connections.
383
- * Db instances are cached so performing db('db1') twice will return the same instance.
384
- * You can control these behaviors with the options noListener and returnNonCachedInstance.
385
381
*
386
382
* @param dbName - The name of the database we want to use. If not provided, use database name from connection string.
387
383
* @param options - Optional settings for Db construction
388
384
*/
389
385
db ( dbName : string ) : Db ;
390
- db ( dbName : string , options : DbOptions & { returnNonCachedInstance ?: boolean } ) : Db ;
391
- db ( dbName : string , options ?: DbOptions & { returnNonCachedInstance ?: boolean } ) : Db {
386
+ db ( dbName : string , options : DbOptions ) : Db ;
387
+ db ( dbName : string , options ?: DbOptions ) : Db {
392
388
options = options ?? { } ;
393
389
394
390
// Default to db from connection string if not provided
@@ -399,12 +395,6 @@ export class MongoClient extends EventEmitter {
399
395
// Copy the options and add out internal override of the not shared flag
400
396
const finalOptions = Object . assign ( { } , this . s . options , options ) ;
401
397
402
- // Do we have the db in the cache already
403
- const dbFromCache = this . s . dbCache . get ( dbName ) ;
404
- if ( dbFromCache && finalOptions . returnNonCachedInstance !== true ) {
405
- return dbFromCache ;
406
- }
407
-
408
398
// If no topology throw an error message
409
399
if ( ! this . topology ) {
410
400
throw new MongoError ( 'MongoClient must be connected before calling MongoClient.prototype.db' ) ;
@@ -413,8 +403,6 @@ export class MongoClient extends EventEmitter {
413
403
// Return the db object
414
404
const db = new Db ( this , dbName , finalOptions ) ;
415
405
416
- // Add the db to the cache
417
- this . s . dbCache . set ( dbName , db ) ;
418
406
// Return the database
419
407
return db ;
420
408
}
0 commit comments