1
1
import type { Document } from '../bson' ;
2
2
import type { Db } from '../db' ;
3
- import { MONGODB_ERROR_CODES , MongoServerError } from '../error' ;
4
3
import type { Server } from '../sdam/server' ;
5
4
import type { ClientSession } from '../sessions' ;
6
5
import { type TimeoutContext } from '../timeout' ;
@@ -16,12 +15,10 @@ export interface DropCollectionOptions extends CommandOperationOptions {
16
15
/** @internal */
17
16
export class DropCollectionOperation extends CommandOperation < boolean > {
18
17
override options : DropCollectionOptions ;
19
- db : Db ;
20
18
name : string ;
21
19
22
20
constructor ( db : Db , name : string , options : DropCollectionOptions = { } ) {
23
21
super ( db , options ) ;
24
- this . db = db ;
25
22
this . options = options ;
26
23
this . name = name ;
27
24
}
@@ -34,53 +31,6 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
34
31
server : Server ,
35
32
session : ClientSession | undefined ,
36
33
timeoutContext : TimeoutContext
37
- ) : Promise < boolean > {
38
- const db = this . db ;
39
- const options = this . options ;
40
- const name = this . name ;
41
-
42
- const encryptedFieldsMap = db . client . s . options . autoEncryption ?. encryptedFieldsMap ;
43
- let encryptedFields : Document | undefined =
44
- options . encryptedFields ?? encryptedFieldsMap ?. [ `${ db . databaseName } .${ name } ` ] ;
45
-
46
- if ( ! encryptedFields && encryptedFieldsMap ) {
47
- // If the MongoClient was configured with an encryptedFieldsMap,
48
- // and no encryptedFields config was available in it or explicitly
49
- // passed as an argument, the spec tells us to look one up using
50
- // listCollections().
51
- const listCollectionsResult = await db
52
- . listCollections ( { name } , { nameOnly : false } )
53
- . toArray ( ) ;
54
- encryptedFields = listCollectionsResult ?. [ 0 ] ?. options ?. encryptedFields ;
55
- }
56
-
57
- if ( encryptedFields ) {
58
- const escCollection = encryptedFields . escCollection || `enxcol_.${ name } .esc` ;
59
- const ecocCollection = encryptedFields . ecocCollection || `enxcol_.${ name } .ecoc` ;
60
-
61
- for ( const collectionName of [ escCollection , ecocCollection ] ) {
62
- // Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
63
- const dropOp = new DropCollectionOperation ( db , collectionName ) ;
64
- try {
65
- await dropOp . executeWithoutEncryptedFieldsCheck ( server , session , timeoutContext ) ;
66
- } catch ( err ) {
67
- if (
68
- ! ( err instanceof MongoServerError ) ||
69
- err . code !== MONGODB_ERROR_CODES . NamespaceNotFound
70
- ) {
71
- throw err ;
72
- }
73
- }
74
- }
75
- }
76
-
77
- return await this . executeWithoutEncryptedFieldsCheck ( server , session , timeoutContext ) ;
78
- }
79
-
80
- private async executeWithoutEncryptedFieldsCheck (
81
- server : Server ,
82
- session : ClientSession | undefined ,
83
- timeoutContext : TimeoutContext
84
34
) : Promise < boolean > {
85
35
await super . executeCommand ( server , session , { drop : this . name } , timeoutContext ) ;
86
36
return true ;
0 commit comments