MCPcopy
hub / github.com/mongodb/node-mongodb-native / dropCollections

Function dropCollections

src/operations/drop.ts:52–102  ·  view source on GitHub ↗
(
  db: Db,
  name: string,
  options: DropCollectionOptions
)

Source from the content-addressed store, hash-verified

50}
51
52export async function dropCollections(
53 db: Db,
54 name: string,
55 options: DropCollectionOptions
56): Promise<boolean> {
57 const timeoutContext = TimeoutContext.create({
58 session: options.session,
59 serverSelectionTimeoutMS: db.client.s.options.serverSelectionTimeoutMS,
60 waitQueueTimeoutMS: db.client.s.options.waitQueueTimeoutMS,
61 timeoutMS: options.timeoutMS
62 });
63
64 const encryptedFieldsMap = db.client.s.options.autoEncryption?.encryptedFieldsMap;
65 let encryptedFields: Document | undefined =
66 options.encryptedFields ?? encryptedFieldsMap?.[`${db.databaseName}.${name}`];
67
68 if (!encryptedFields && encryptedFieldsMap) {
69 // If the MongoClient was configured with an encryptedFieldsMap,
70 // and no encryptedFields config was available in it or explicitly
71 // passed as an argument, the spec tells us to look one up using
72 // listCollections().
73 const listCollectionsResult = await db
74 .listCollections(
75 { name },
76 {
77 nameOnly: false,
78 session: options.session,
79 timeoutContext: new CursorTimeoutContext(timeoutContext, Symbol())
80 }
81 )
82 .toArray();
83 encryptedFields = listCollectionsResult?.[0]?.options?.encryptedFields;
84 }
85
86 if (encryptedFields) {
87 const escCollection = encryptedFields.escCollection || `enxcol_.${name}.esc`;
88 const ecocCollection = encryptedFields.ecocCollection || `enxcol_.${name}.ecoc`;
89
90 for (const collectionName of [escCollection, ecocCollection]) {
91 // Drop auxilliary collections, ignoring potential NamespaceNotFound errors.
92 const dropOp = new DropCollectionOperation(db, collectionName, options);
93 await executeOperation(db.client, dropOp, timeoutContext);
94 }
95 }
96
97 return await executeOperation(
98 db.client,
99 new DropCollectionOperation(db, name, options),
100 timeoutContext
101 );
102}
103
104/** @public */
105export type DropDatabaseOptions = CommandOperationOptions;

Callers 1

dropCollectionMethod · 0.90

Calls 3

executeOperationFunction · 0.90
toArrayMethod · 0.80
listCollectionsMethod · 0.80

Tested by

no test coverage detected