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