11import type { Document } from '../bson' ;
22import type { Db } from '../db' ;
3- import { MONGODB_ERROR_CODES , MongoServerError } from '../error' ;
43import type { Server } from '../sdam/server' ;
54import type { ClientSession } from '../sessions' ;
65import { type TimeoutContext } from '../timeout' ;
@@ -16,12 +15,10 @@ export interface DropCollectionOptions extends CommandOperationOptions {
1615/** @internal */
1716export class DropCollectionOperation extends CommandOperation < boolean > {
1817 override options : DropCollectionOptions ;
19- db : Db ;
2018 name : string ;
2119
2220 constructor ( db : Db , name : string , options : DropCollectionOptions = { } ) {
2321 super ( db , options ) ;
24- this . db = db ;
2522 this . options = options ;
2623 this . name = name ;
2724 }
@@ -34,53 +31,6 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
3431 server : Server ,
3532 session : ClientSession | undefined ,
3633 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
8434 ) : Promise < boolean > {
8535 await super . executeCommand ( server , session , { drop : this . name } , timeoutContext ) ;
8636 return true ;
0 commit comments