@@ -3,11 +3,10 @@ import { type BSONSerializeOptions, type Document, resolveBSONOptions } from './
3
3
import { ChangeStream , type ChangeStreamDocument , type ChangeStreamOptions } from './change_stream' ;
4
4
import { Collection , type CollectionOptions } from './collection' ;
5
5
import * as CONSTANTS from './constants' ;
6
- import { CursorTimeoutContext } from './cursor/abstract_cursor' ;
7
6
import { AggregationCursor } from './cursor/aggregation_cursor' ;
8
7
import { ListCollectionsCursor } from './cursor/list_collections_cursor' ;
9
8
import { RunCommandCursor , type RunCursorCommandOptions } from './cursor/run_command_cursor' ;
10
- import { MONGODB_ERROR_CODES , MongoInvalidArgumentError , MongoServerError } from './error' ;
9
+ import { MongoInvalidArgumentError } from './error' ;
11
10
import type { MongoClient , PkFactory } from './mongo_client' ;
12
11
import type { Abortable , TODO_NODE_3286 } from './mongo_types' ;
13
12
import type { AggregateOptions } from './operations/aggregate' ;
@@ -16,8 +15,8 @@ import {
16
15
type CreateCollectionOptions
17
16
} from './operations/create_collection' ;
18
17
import {
19
- DropCollectionOperation ,
20
18
type DropCollectionOptions ,
19
+ dropCollections ,
21
20
DropDatabaseOperation ,
22
21
type DropDatabaseOptions
23
22
} from './operations/drop' ;
@@ -43,7 +42,6 @@ import {
43
42
import { DbStatsOperation , type DbStatsOptions } from './operations/stats' ;
44
43
import { ReadConcern } from './read_concern' ;
45
44
import { ReadPreference , type ReadPreferenceLike } from './read_preference' ;
46
- import { TimeoutContext } from './timeout' ;
47
45
import { DEFAULT_PK_FACTORY , filterOptions , MongoDBNamespace , resolveOptions } from './utils' ;
48
46
import { WriteConcern , type WriteConcernOptions } from './write_concern' ;
49
47
@@ -361,13 +359,13 @@ export class Db {
361
359
) : ListCollectionsCursor < CollectionInfo > ;
362
360
listCollections <
363
361
T extends Pick < CollectionInfo , 'name' | 'type' > | CollectionInfo =
364
- | Pick < CollectionInfo , 'name' | 'type' >
365
- | CollectionInfo
362
+ | Pick < CollectionInfo , 'name' | 'type' >
363
+ | CollectionInfo
366
364
> ( filter ?: Document , options ?: ListCollectionsOptions & Abortable ) : ListCollectionsCursor < T > ;
367
365
listCollections <
368
366
T extends Pick < CollectionInfo , 'name' | 'type' > | CollectionInfo =
369
- | Pick < CollectionInfo , 'name' | 'type' >
370
- | CollectionInfo
367
+ | Pick < CollectionInfo , 'name' | 'type' >
368
+ | CollectionInfo
371
369
> (
372
370
filter : Document = { } ,
373
371
options : ListCollectionsOptions & Abortable = { }
@@ -412,61 +410,15 @@ export class Db {
412
410
* @param options - Optional settings for the command
413
411
*/
414
412
async dropCollection ( name : string , options ?: DropCollectionOptions ) : Promise < boolean > {
415
- options = resolveOptions ( this , options ) ;
416
- options . session ??= this . client . startSession ( { owner : Symbol ( ) , explicit : false } ) ;
417
-
418
- const timeoutContext = TimeoutContext . create ( {
419
- session : options . session ,
420
- serverSelectionTimeoutMS : this . client . s . options . serverSelectionTimeoutMS ,
421
- waitQueueTimeoutMS : this . client . s . options . waitQueueTimeoutMS ,
422
- timeoutMS : options . timeoutMS
423
- } ) ;
424
-
425
- const encryptedFieldsMap = this . client . s . options . autoEncryption ?. encryptedFieldsMap ;
426
- let encryptedFields : Document | undefined =
427
- options . encryptedFields ?? encryptedFieldsMap ?. [ `${ this . databaseName } .${ name } ` ] ;
428
-
429
- if ( ! encryptedFields && encryptedFieldsMap ) {
430
- // If the MongoClient was configured with an encryptedFieldsMap,
431
- // and no encryptedFields config was available in it or explicitly
432
- // passed as an argument, the spec tells us to look one up using
433
- // listCollections().
434
- const listCollectionsResult = await this . listCollections (
435
- { name } ,
436
- {
437
- nameOnly : false ,
438
- session : options . session ,
439
- timeoutContext : new CursorTimeoutContext ( timeoutContext , Symbol ( ) )
440
- }
441
- ) . toArray ( ) ;
442
- encryptedFields = listCollectionsResult ?. [ 0 ] ?. options ?. encryptedFields ;
443
- }
444
-
445
- if ( encryptedFields ) {
446
- const escCollection = encryptedFields . escCollection || `enxcol_.${ name } .esc` ;
447
- const ecocCollection = encryptedFields . ecocCollection || `enxcol_.${ name } .ecoc` ;
448
-
449
- for ( const collectionName of [ escCollection , ecocCollection ] ) {
450
- // Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
451
- const dropOp = new DropCollectionOperation ( this , collectionName , options ) ;
452
- try {
453
- await executeOperation ( this . client , dropOp , timeoutContext ) ;
454
- } catch ( err ) {
455
- if (
456
- ! ( err instanceof MongoServerError ) ||
457
- err . code !== MONGODB_ERROR_CODES . NamespaceNotFound
458
- ) {
459
- throw err ;
460
- }
461
- }
462
- }
413
+ options = resolveOptions ( this , { ...options } ) ;
414
+ if ( options . session ) {
415
+ return await dropCollections ( this , name , options ) ;
463
416
}
464
417
465
- return await executeOperation (
466
- this . client ,
467
- new DropCollectionOperation ( this , name , options ) ,
468
- timeoutContext
469
- ) ;
418
+ return await this . client . withSession ( { explicit : false } , async session => {
419
+ options . session = session ;
420
+ return await dropCollections ( this , name , options ) ;
421
+ } ) ;
470
422
}
471
423
472
424
/**
0 commit comments