diff --git a/src/operations/drop.ts b/src/operations/drop.ts index 55312392626..5733b6b956d 100644 --- a/src/operations/drop.ts +++ b/src/operations/drop.ts @@ -1,4 +1,4 @@ -import { type Connection, MongoServerError } from '..'; +import { type Connection, type MongoError, MongoServerError } from '..'; import type { Document } from '../bson'; import { MongoDBResponse } from '../cmap/wire_protocol/responses'; import { CursorTimeoutContext } from '../cursor/abstract_cursor'; @@ -40,6 +40,13 @@ export class DropCollectionOperation extends CommandOperation { override handleOk(_response: InstanceType): boolean { return true; } + + override handleError(error: MongoError): boolean { + if (!(error instanceof MongoServerError)) throw error; + if (Number(error.code) !== MONGODB_ERROR_CODES.NamespaceNotFound) throw error; + + return false; + } } export async function dropCollections( @@ -83,16 +90,7 @@ export async function dropCollections( for (const collectionName of [escCollection, ecocCollection]) { // Drop auxilliary collections, ignoring potential NamespaceNotFound errors. const dropOp = new DropCollectionOperation(db, collectionName, options); - try { - await executeOperation(db.client, dropOp, timeoutContext); - } catch (err) { - if ( - !(err instanceof MongoServerError) || - err.code !== MONGODB_ERROR_CODES.NamespaceNotFound - ) { - throw err; - } - } + await executeOperation(db.client, dropOp, timeoutContext); } } diff --git a/test/benchmarks/driver_bench/src/driver.mts b/test/benchmarks/driver_bench/src/driver.mts index d21048cf8f7..1089232a75b 100644 --- a/test/benchmarks/driver_bench/src/driver.mts +++ b/test/benchmarks/driver_bench/src/driver.mts @@ -202,7 +202,7 @@ export class DriverTester { const utilClient = new MongoClient(MONGODB_URI, MONGODB_CLIENT_OPTIONS); const db = utilClient.db(DB_NAME); const collection = db.collection(COLLECTION_NAME); - await collection.drop().catch(() => null); + await collection.drop(); await db.dropDatabase().catch(() => null); await utilClient.close(); } diff --git a/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_download.mts b/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_download.mts index 67b1c802517..e5e581a294b 100644 --- a/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_download.mts +++ b/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_download.mts @@ -20,7 +20,7 @@ export async function before() { bucket = driver.bucket(driver.client.db(driver.DB_NAME)); - await bucket.drop().catch(() => null); + await bucket.drop(); // Create the bucket. const stream = bucket.openUploadStream('gridfstest'); diff --git a/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_upload.mts b/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_upload.mts index 002c530ec01..64edb780fd5 100644 --- a/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_upload.mts +++ b/test/benchmarks/driver_bench/src/suites/multi_bench/grid_fs_upload.mts @@ -18,7 +18,7 @@ export async function before() { bucket = driver.bucket(driver.client.db(driver.DB_NAME)); - await bucket.drop().catch(() => null); + await bucket.drop(); } export async function beforeEach() { diff --git a/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_download.mts b/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_download.mts index 656919ed9b2..2bd52163be1 100644 --- a/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_download.mts +++ b/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_download.mts @@ -15,7 +15,7 @@ export async function before() { await driver.resetTmpDir(); bucket = driver.bucket(driver.client.db(driver.DB_NAME)); - await bucket.drop().catch(() => null); + await bucket.drop(); const gridfs_multi = path.resolve(PARALLEL_DIRECTORY, 'gridfs_multi'); diff --git a/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_upload.mts b/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_upload.mts index 0942f6bc414..a5a705c9fa0 100644 --- a/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_upload.mts +++ b/test/benchmarks/driver_bench/src/suites/parallel_bench/gridfs_multi_file_upload.mts @@ -18,7 +18,7 @@ export async function before() { bucket = driver.bucket(driver.client.db(driver.DB_NAME)); - await bucket.drop().catch(() => null); + await bucket.drop(); } export async function beforeEach() { diff --git a/test/integration/change-streams/change_stream.test.ts b/test/integration/change-streams/change_stream.test.ts index a30ca19ed7a..bc844e339d6 100644 --- a/test/integration/change-streams/change_stream.test.ts +++ b/test/integration/change-streams/change_stream.test.ts @@ -563,7 +563,7 @@ describe('Change Streams', function () { async test() { const collection = db.collection('resumeAfterTest2'); - await collection.drop().catch(() => null); + await collection.drop(); let resumeToken; const docs = [{ a: 0 }, { a: 1 }, { a: 2 }]; diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts index 41c7c8cb94c..85e4492a708 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts @@ -143,13 +143,7 @@ describe('Client Side Encryption Prose Corpus Test', function () { await client.connect(); // 3. Using ``client``, drop the collection ``keyvault.datakeys``. Insert the documents `corpus/corpus-key-local.json <../corpus/corpus-key-local.json>`_ and `corpus/corpus-key-aws.json <../corpus/corpus-key-aws.json>`_. const keyDb = client.db(keyVaultDbName); - await keyDb - .dropCollection(keyVaultCollName, { writeConcern: new WriteConcern('majority') }) - .catch((e: Error) => { - if (!/ns/i.test(e.message)) { - throw e; - } - }); + await keyDb.dropCollection(keyVaultCollName, { writeConcern: new WriteConcern('majority') }); const keyColl = keyDb.collection(keyVaultCollName); await keyColl.insertMany( [corpusKeyLocal, corpusKeyAws, corpusKeyAzure, corpusKeyGcp, corpusKeyKmip], @@ -164,13 +158,7 @@ describe('Client Side Encryption Prose Corpus Test', function () { beforeEach(async function () { // 2. Using ``client``, drop and create the collection ``db.coll`` configured with the included JSON schema `corpus/corpus-schema.json <../corpus/corpus-schema.json>`_. const dataDb = client.db(dataDbName); - await dataDb - .dropCollection(dataCollName, { writeConcern: new WriteConcern('majority') }) - .catch((e: Error) => { - if (!/ns/i.test(e.message)) { - throw e; - } - }); + await dataDb.dropCollection(dataCollName, { writeConcern: new WriteConcern('majority') }); await dataDb.createCollection(dataCollName, { validator: { $jsonSchema: corpusSchema }, writeConcern: new WriteConcern('majority') diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts index 9901cb08820..9412f78c9b8 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.14.decryption_events.test.ts @@ -43,7 +43,7 @@ describe('14. Decryption Events', metadata, function () { .collection('decryption_events') .deleteMany({}) .catch(() => null); - await db.dropCollection('decryption_events').catch(() => null); + await db.dropCollection('decryption_events'); await db.createCollection('decryption_events'); // Create a ClientEncryption object named ``clientEncryption`` with these options: // ClientEncryptionOpts { diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts index c78fb4a9fab..12b00cce19d 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.22.range_explicit_encryption.test.ts @@ -171,26 +171,12 @@ describe('Range Explicit Encryption', function () { await utilClient.db('db').dropDatabase(); - await utilClient - .db('db') - .dropCollection('explicit_encryption') - .catch(e => { - if (!/ns not found/.test(e.message)) { - throw e; - } - }); + await utilClient.db('db').dropCollection('explicit_encryption'); await utilClient.db('db').createCollection('explicit_encryption', { encryptedFields }); - await utilClient - .db('keyvault') - .dropCollection('datakeys') - .catch(e => { - if (!/ns not found/.test(e.message)) { - throw e; - } - }); + await utilClient.db('keyvault').dropCollection('datakeys'); await utilClient.db('keyvault').createCollection('datakeys'); diff --git a/test/integration/client-side-encryption/client_side_encryption.prose.test.ts b/test/integration/client-side-encryption/client_side_encryption.prose.test.ts index 47bc3a101a1..b76687eccc7 100644 --- a/test/integration/client-side-encryption/client_side_encryption.prose.test.ts +++ b/test/integration/client-side-encryption/client_side_encryption.prose.test.ts @@ -2239,10 +2239,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () { await client.connect(); // Using client, drop the collection keyvault.datakeys. - await client - .db('keyvault') - .dropCollection('datakeys') - .catch(() => null); + await client.db('keyvault').dropCollection('datakeys'); await client .db('keyvault') @@ -2389,10 +2386,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () { client1.mongoLogger?.trace('client', 'dropping datakeys collection'); // Step 1. Drop the collection ``keyvault.datakeys`` - await client1 - .db('keyvault') - .dropCollection('datakeys') - .catch(() => null); + await client1.db('keyvault').dropCollection('datakeys'); client1.mongoLogger?.trace('client', 'dropped datakeys collection'); diff --git a/test/integration/client-side-encryption/driver.test.ts b/test/integration/client-side-encryption/driver.test.ts index a7a5a9f8e7d..02fe82d336e 100644 --- a/test/integration/client-side-encryption/driver.test.ts +++ b/test/integration/client-side-encryption/driver.test.ts @@ -130,8 +130,8 @@ describe('Client Side Encryption Functional', function () { const dataDb = client.db(dataDbName); const keyVaultDb = client.db(keyVaultDbName); - await dataDb.dropCollection(dataCollName).catch(() => null); - await keyVaultDb.dropCollection(keyVaultCollName).catch(() => null); + await dataDb.dropCollection(dataCollName); + await keyVaultDb.dropCollection(keyVaultCollName); await keyVaultDb.createCollection(keyVaultCollName); const dataKey = await encryption.createDataKey('local'); @@ -314,8 +314,8 @@ describe('Client Side Encryption Functional', function () { const dataDb = client.db(dataDbName); const keyVaultDb = client.db(keyVaultDbName); - await dataDb.dropCollection(dataCollName).catch(() => null); - await keyVaultDb.dropCollection(keyVaultCollName).catch(() => null); + await dataDb.dropCollection(dataCollName); + await keyVaultDb.dropCollection(keyVaultCollName); await keyVaultDb.createCollection(keyVaultCollName); const dataKey = await encryption.createDataKey('local'); @@ -448,8 +448,7 @@ describe('Client Side Encryption Functional', function () { const internalClient = this.configuration.newClient(); await internalClient .db('keyvault') - .dropCollection('datakeys', { writeConcern: { w: 'majority' } }) - .catch(() => null); + .dropCollection('datakeys', { writeConcern: { w: 'majority' } }); await internalClient.db('keyvault').createCollection('datakeys'); await internalClient.close(); @@ -1121,16 +1120,8 @@ describe('CSOT', function () { configureFailPoint: 'failCommand', mode: 'off' } as FailCommandFailPoint); - await client - .db('db') - .collection('newnew') - .drop() - .catch(() => null); - await client - .db('keyvault') - .collection('datakeys') - .drop() - .catch(() => null); + await client.db('db').collection('newnew').drop(); + await client.db('keyvault').collection('datakeys').drop(); await client.close(); }); diff --git a/test/integration/command-logging-and-monitoring/command_monitoring.test.ts b/test/integration/command-logging-and-monitoring/command_monitoring.test.ts index 240a9363064..b089ca7d65f 100644 --- a/test/integration/command-logging-and-monitoring/command_monitoring.test.ts +++ b/test/integration/command-logging-and-monitoring/command_monitoring.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { type MongoClient, ObjectId, ReadPreference } from '../../mongodb'; -import { filterForCommands, ignoreNsNotFound, setupDatabase } from '../shared'; +import { filterForCommands, setupDatabase } from '../shared'; describe('Command Monitoring', function () { let client: MongoClient; @@ -164,7 +164,6 @@ describe('Command Monitoring', function () { return db .collection('apm_test_2') .drop() - .catch(ignoreNsNotFound) .then(() => { // Insert test documents return db @@ -235,7 +234,6 @@ describe('Command Monitoring', function () { return db .collection('apm_test_2') .drop() - .catch(ignoreNsNotFound) .then(() => { // Insert test documents return db @@ -328,7 +326,6 @@ describe('Command Monitoring', function () { return db .collection('apm_test_2') .drop() - .catch(ignoreNsNotFound) .then(() => db .collection('apm_test_2') @@ -531,12 +528,10 @@ describe('Command Monitoring', function () { const desiredEvents = ['aggregate', 'getMore']; client.on('commandStarted', filterForCommands(desiredEvents, started)); client.on('commandSucceeded', filterForCommands(desiredEvents, succeeded)); - const db = client.db(this.configuration.db); return db .collection('apm_test_u_4') .drop() - .catch(ignoreNsNotFound) .then(() => db.collection('apm_test_u_4').insertMany(docs)) .then(r => { expect(r).to.exist; diff --git a/test/integration/connections-survive-step-down/connections_survive_step_down.prose.test.ts b/test/integration/connections-survive-step-down/connections_survive_step_down.prose.test.ts index 8e409a18a63..3ba24d95870 100644 --- a/test/integration/connections-survive-step-down/connections_survive_step_down.prose.test.ts +++ b/test/integration/connections-survive-step-down/connections_survive_step_down.prose.test.ts @@ -33,7 +33,7 @@ describe('Connections Survive Primary Step Down - prose', function () { // - Create a collection object from the ``MongoClient``, using ``step-down`` for the database and collection name. collection = client.db('step-down').collection('step-down'); // - Drop the test collection, using ``writeConcern`` "majority". - await collection.drop({ writeConcern: { w: 'majority' } }).catch(() => null); + await collection.drop({ writeConcern: { w: 'majority' } }); // - Execute the "create" command to recreate the collection, using writeConcern: "majority". collection = await client .db('step-down') diff --git a/test/integration/crud/bulk.test.ts b/test/integration/crud/bulk.test.ts index 6dc1b1beb26..1d9b6c3da27 100644 --- a/test/integration/crud/bulk.test.ts +++ b/test/integration/crud/bulk.test.ts @@ -12,7 +12,7 @@ import { MongoDriverError, MongoInvalidArgumentError } from '../../../src'; -import { assert as test, ignoreNsNotFound } from '../shared'; +import { assert as test } from '../shared'; const MAX_BSON_SIZE = 16777216; const DB_NAME = 'bulk_operations_tests'; @@ -1432,9 +1432,7 @@ describe('Bulk', function () { const documents = [{ s: largeString }, { s: largeString }]; const db = client.db(); - await db.dropCollection('doesnt_matter').catch(() => { - // ignore - }); + await db.dropCollection('doesnt_matter'); await db.createCollection('doesnt_matter'); const coll = db.collection('doesnt_matter'); await coll.insertMany(documents, { ordered: true }); @@ -1446,9 +1444,7 @@ describe('Bulk', function () { const documents = [{ s: largeString }, { s: largeString }]; const db = client.db(); - await db.dropCollection('doesnt_matter').catch(() => { - // ignore - }); + await db.dropCollection('doesnt_matter'); await db.createCollection('doesnt_matter'); const coll = db.collection('doesnt_matter'); await coll.insertMany(documents, { ordered: false }); @@ -1474,7 +1470,7 @@ describe('Bulk', function () { it('should promote a single error to the top-level message, and preserve writeErrors', async function () { const coll = client.db().collection<{ _id: number; a: number }>('single_bulk_write_error'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); await coll.insertMany(Array.from({ length: 4 }, (_, i) => ({ _id: i, a: i }))); const err = await coll .bulkWrite([ @@ -1490,7 +1486,7 @@ describe('Bulk', function () { it('should preserve order of operation index in unordered bulkWrite', async function () { const coll = client.db().collection<{ _id: number; a: number }>('bulk_write_ordering_test'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); await coll.insertMany(Array.from({ length: 4 }, (_, i) => ({ _id: i, a: i }))); await coll.createIndex({ a: 1 }, { unique: true }); const err = await coll @@ -1513,7 +1509,7 @@ describe('Bulk', function () { it('should preserve order of operation index in unordered bulk operation', async function () { const coll = client.db().collection('unordered_preserve_order'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); const batch = coll.initializeUnorderedBulkOp(); batch.insert({ _id: 1, a: 0 }); batch.insert({ _id: 1, a: 0 }); @@ -1528,7 +1524,7 @@ describe('Bulk', function () { it('should not fail on the first error in an unorderd bulkWrite', async function () { const coll = client.db().collection('bulk_op_ordering_test'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); await coll.createIndex({ email: 1 }, { unique: true, background: false }); await Promise.all([ coll.updateOne( diff --git a/test/integration/crud/crud_api.test.ts b/test/integration/crud/crud_api.test.ts index e6512b6f13f..d4163d32cb0 100644 --- a/test/integration/crud/crud_api.test.ts +++ b/test/integration/crud/crud_api.test.ts @@ -89,12 +89,12 @@ describe('CRUD API', function () { ); collection = client.db('findOne').collection('findOne'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany([{ _id: 1 }, { _id: 2 }]); }); afterEach(async () => { - await collection.drop().catch(() => null); + await collection.drop(); await client.close(); }); @@ -159,12 +159,12 @@ describe('CRUD API', function () { ); collection = client.db('countDocuments').collection('countDocuments'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany([{ _id: 1 }, { _id: 2 }]); }); afterEach(async () => { - await collection.drop().catch(() => null); + await collection.drop(); await client.close(); }); @@ -218,12 +218,12 @@ describe('CRUD API', function () { beforeEach(async () => { collection = client.db().collection('t'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany([{ a: 1 }, { a: 1 }, { a: 1 }, { a: 1 }]); }); afterEach(async () => { - await collection?.drop().catch(() => null); + await collection?.drop(); }); const makeCursor = () => { @@ -881,12 +881,12 @@ describe('CRUD API', function () { ); collection = client.db('updateManyTest').collection('updateManyTest'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany([{ a: 1 }, { a: 2 }]); }); afterEach(async function () { - await collection.drop().catch(() => null); + await collection.drop(); await client.close(); }); diff --git a/test/integration/crud/document_validation.test.ts b/test/integration/crud/document_validation.test.ts index ec60976e420..ce6ac49522a 100644 --- a/test/integration/crud/document_validation.test.ts +++ b/test/integration/crud/document_validation.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { MongoBulkWriteError, type MongoClient, MongoServerError } from '../../../src'; -import { ignoreNsNotFound, setupDatabase } from '../shared'; +import { setupDatabase } from '../shared'; describe('Document Validation', function () { let client: MongoClient; @@ -28,7 +28,7 @@ describe('Document Validation', function () { const col = db.collection('createValidationCollection'); // Drop the collection - await col.drop().catch(ignoreNsNotFound); + await col.drop(); // Create a collection with a validator await db.createCollection('createValidationCollection', { validator: { a: { $exists: true } } @@ -56,7 +56,7 @@ describe('Document Validation', function () { const col = db.collection('createValidationCollection'); // Drop the collection - await col.drop().catch(ignoreNsNotFound); + await col.drop(); // Create a collection with a validator await db.createCollection('createValidationCollection', { validator: { a: { $exists: true } } @@ -97,7 +97,7 @@ describe('Document Validation', function () { const col = db.collection('createValidationCollection'); // Drop the collection - await col.drop().catch(ignoreNsNotFound); + await col.drop(); // Create a collection with a validator await db.createCollection('createValidationCollection', { validator: { a: { $exists: true } } @@ -123,7 +123,7 @@ describe('Document Validation', function () { const col = db.collection('createValidationCollection'); // Drop the collection - await col.drop().catch(ignoreNsNotFound); + await col.drop(); // Create a collection with a validator await db.createCollection('createValidationCollection', { validator: { a: { $exists: true } } @@ -176,7 +176,7 @@ describe('Document Validation', function () { const col = db.collection('createValidationCollectionOut'); // Drop the collection - await col.drop().catch(ignoreNsNotFound); + await col.drop(); // Create a collection with a validator await db.createCollection('createValidationCollectionOut', { validator: { a: { $exists: true } } diff --git a/test/integration/crud/find.test.ts b/test/integration/crud/find.test.ts index 557c7002573..9b794366ec8 100644 --- a/test/integration/crud/find.test.ts +++ b/test/integration/crud/find.test.ts @@ -38,7 +38,7 @@ describe('Find', function () { const configuration = this.configuration; const db = client.db(configuration.db); - await db.dropCollection('test_find_simple').catch(() => null); + await db.dropCollection('test_find_simple'); const collection = db.collection('test_find_simple'); const docs = [{ a: 2 }, { b: 3 }]; @@ -101,7 +101,7 @@ describe('Find', function () { const configuration = this.configuration; const db = client.db(configuration.db); - await db.dropCollection('test_find_advanced').catch(() => null); + await db.dropCollection('test_find_advanced'); const collection = db.collection('test_find_advanced'); const docs = [{ a: 1 }, { a: 2 }, { b: 3 }]; diff --git a/test/integration/crud/find_cursor_methods.test.ts b/test/integration/crud/find_cursor_methods.test.ts index 96d0c4ff249..9a9c2569a55 100644 --- a/test/integration/crud/find_cursor_methods.test.ts +++ b/test/integration/crud/find_cursor_methods.test.ts @@ -20,8 +20,8 @@ describe('Find Cursor', function () { const docs = [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }, { a: 6 }]; const coll = setupClient.db().collection('abstract_cursor'); const tryNextColl = setupClient.db().collection('try_next'); - await coll.drop().catch(() => null); - await tryNextColl.drop().catch(() => null); + await coll.drop(); + await tryNextColl.drop(); await coll.insertMany(docs); await setupClient.close(); }); @@ -121,12 +121,12 @@ describe('Find Cursor', function () { beforeEach(async function () { collection = client.db().collection('abstract_cursor'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }]); }); afterEach(async function () { - await collection?.drop().catch(() => null); + await collection?.drop(); }); context('when closed before completely iterated', () => { diff --git a/test/integration/crud/insert.test.ts b/test/integration/crud/insert.test.ts index 0fe0983b4d0..d491119e756 100644 --- a/test/integration/crud/insert.test.ts +++ b/test/integration/crud/insert.test.ts @@ -23,7 +23,7 @@ import { Timestamp } from '../../../src'; import { noop } from '../../../src/utils'; -import { assert as test, ignoreNsNotFound, setupDatabase } from '../shared'; +import { assert as test, setupDatabase } from '../shared'; describe('crud - insert', function () { let client: MongoClient; @@ -1463,7 +1463,7 @@ describe('crud - insert', function () { it('should return error on unordered insertMany with multiple unique key constraints', async () => { const col = client.db().collection('insertManyMultipleWriteErrors'); - await col.drop().catch(() => null); + await col.drop(); const createIndexRes = await col.createIndex({ a: 1 }, { unique: true }); expect(createIndexRes).to.equal('a_1'); @@ -1481,7 +1481,7 @@ describe('crud - insert', function () { it('should return error on ordered insertMany with multiple unique key constraints', async () => { const col = client.db().collection('insertManyMultipleWriteErrors'); - await col.drop().catch(() => null); + await col.drop(); const createIndexRes = await col.createIndex({ a: 1 }, { unique: true }); expect(createIndexRes).to.equal('a_1'); @@ -1590,7 +1590,7 @@ describe('crud - insert', function () { }); it('MongoBulkWriteError and BulkWriteResult should respect BulkWrite', async function () { - await client.db().collection('test_insertMany_bulkResult').drop().catch(ignoreNsNotFound); + await client.db().collection('test_insertMany_bulkResult').drop(); const collection = client .db() diff --git a/test/integration/crud/maxTimeMS.test.ts b/test/integration/crud/maxTimeMS.test.ts index 6acc67a1291..f4d83ddc2f3 100644 --- a/test/integration/crud/maxTimeMS.test.ts +++ b/test/integration/crud/maxTimeMS.test.ts @@ -88,10 +88,7 @@ describe('MaxTimeMS', function () { beforeEach(async function () { client = this.configuration.newClient({ monitorCommands: true }); - await client - .db() - .dropCollection('cappedAt3') - .catch(() => null); + await client.db().dropCollection('cappedAt3'); cappedCollection = await client .db() .createCollection('cappedAt3', { capped: true, size: 4096, max: 3 }); diff --git a/test/integration/crud/misc_cursors.test.js b/test/integration/crud/misc_cursors.test.js index d5a82ec3466..3e3ef1a2f8d 100644 --- a/test/integration/crud/misc_cursors.test.js +++ b/test/integration/crud/misc_cursors.test.js @@ -1698,7 +1698,7 @@ describe('Cursor', function () { it('destroying a stream stops it', async function () { const db = client.db(); - await db.dropCollection('destroying_a_stream_stops_it').catch(() => null); + await db.dropCollection('destroying_a_stream_stops_it'); const collection = await db.createCollection('destroying_a_stream_stops_it'); const docs = Array.from({ length: 10 }, (_, i) => ({ b: i + 1 })); @@ -1852,10 +1852,7 @@ describe('Cursor', function () { 'closes cursors when client is closed even if it has not been exhausted', { requires: { topology: '!replicaset' } }, async function () { - await client - .db() - .dropCollection('test_cleanup_tailable') - .catch(() => null); + await client.db().dropCollection('test_cleanup_tailable'); const collection = await client .db() diff --git a/test/integration/gridfs/gridfs.test.ts b/test/integration/gridfs/gridfs.test.ts index f75a819d1a2..2883b863947 100644 --- a/test/integration/gridfs/gridfs.test.ts +++ b/test/integration/gridfs/gridfs.test.ts @@ -22,9 +22,9 @@ describe('GridFS', () => { db = client.db('gridfsTest'); // Reset namespace - await db.dropCollection('fs.files').catch(() => null); - await db.dropCollection('fs.chunks').catch(() => null); - await db.dropDatabase().catch(() => null); + await db.dropCollection('fs.files'); + await db.dropCollection('fs.chunks'); + await db.dropDatabase(); await sleep(100); commandStartedEvents = []; diff --git a/test/integration/node-specific/abort_signal.test.ts b/test/integration/node-specific/abort_signal.test.ts index c128156f2e2..6cec61ec391 100644 --- a/test/integration/node-specific/abort_signal.test.ts +++ b/test/integration/node-specific/abort_signal.test.ts @@ -233,7 +233,7 @@ describe('AbortSignal support', () => { const utilClient = this.configuration.newClient(); try { const collection = utilClient.db('abortSignal').collection('support'); - await collection.drop({}).catch(() => null); + await collection.drop({}); await collection.insertMany([ { a: 1, ssn: '0000-00-0001' }, { a: 2, ssn: '0000-00-0002' }, @@ -241,7 +241,7 @@ describe('AbortSignal support', () => { ]); if (cursorName === 'listCollections') { for (let i = 0; i < 3; i++) { - await db.dropCollection(`c${i}`).catch(() => null); + await db.dropCollection(`c${i}`); await db.createCollection(`c${i}`); } } @@ -535,7 +535,7 @@ describe('AbortSignal support', () => { const utilClient = this.configuration.newClient(); try { const collection = utilClient.db('abortSignal').collection('support'); - await collection.drop({}).catch(() => null); + await collection.drop({}); await collection.insertMany([ { a: 1, ssn: '0000-00-0001' }, { a: 2, ssn: '0000-00-0002' }, @@ -570,7 +570,7 @@ describe('AbortSignal support', () => { const utilClient = this.configuration.newClient(); try { const collection = utilClient.db('abortSignal').collection('support'); - await collection.drop({}).catch(() => null); + await collection.drop({}); await collection.insertMany([ { a: 1, ssn: '0000-00-0001' }, { a: 2, ssn: '0000-00-0002' }, diff --git a/test/integration/node-specific/abstract_cursor.test.ts b/test/integration/node-specific/abstract_cursor.test.ts index 94320283954..3a39cfe03e5 100644 --- a/test/integration/node-specific/abstract_cursor.test.ts +++ b/test/integration/node-specific/abstract_cursor.test.ts @@ -596,7 +596,7 @@ describe('class AbstractCursor', function () { beforeEach(async function () { client = this.configuration.newClient(); collection = client.db('activeCursors').collection('activeCursors'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany(Array.from({ length: 50 }, (_, i) => ({ i }))); }); diff --git a/test/integration/node-specific/bson-options/ignore_undefined.test.ts b/test/integration/node-specific/bson-options/ignore_undefined.test.ts index fd7c5cc18d4..5b7593a1644 100644 --- a/test/integration/node-specific/bson-options/ignore_undefined.test.ts +++ b/test/integration/node-specific/bson-options/ignore_undefined.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { type MongoClient, ObjectId } from '../../../../src'; -import { assert as test, ignoreNsNotFound, setupDatabase } from '../../shared'; +import { assert as test, setupDatabase } from '../../shared'; describe('Ignore Undefined', function () { before(function () { @@ -181,7 +181,7 @@ describe('Ignore Undefined', function () { describe('ignoreUndefined A server', function () { it('should correctly execute insert culling undefined', async function () { const coll = client.db().collection('insert1'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); const objectId = new ObjectId(); const res = await coll.insertOne( { _id: objectId, a: 1, b: undefined }, @@ -197,7 +197,7 @@ describe('Ignore Undefined', function () { it('should correctly execute update culling undefined', async function () { const coll = client.db().collection('update1'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); const objectId = new ObjectId(); const res = await coll.updateOne( { _id: objectId, a: 1, b: undefined }, @@ -214,7 +214,7 @@ describe('Ignore Undefined', function () { it('should correctly execute remove culling undefined', async function () { const coll = client.db().collection('remove1'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); const objectId = new ObjectId(); const res = await coll.insertMany([ { id: objectId, a: 1, b: undefined }, @@ -228,7 +228,7 @@ describe('Ignore Undefined', function () { it('should correctly execute remove not culling undefined', async function () { const coll = client.db().collection('remove1'); - await coll.drop().catch(ignoreNsNotFound); + await coll.drop(); const objectId = new ObjectId(); const res = await coll.insertMany([ { id: objectId, a: 1, b: undefined }, diff --git a/test/integration/node-specific/bson-options/raw.test.ts b/test/integration/node-specific/bson-options/raw.test.ts index 91f6423f3f2..455344f9a92 100644 --- a/test/integration/node-specific/bson-options/raw.test.ts +++ b/test/integration/node-specific/bson-options/raw.test.ts @@ -41,7 +41,7 @@ describe('raw bson support', () => { beforeEach(async function () { client = this.configuration.newClient(); collection = client.db('test_raw').collection('test_raw'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertOne({ _id: 1, myData: 'hello' }); await collection.insertOne({ _id: 2, myData: 'bye bye' }); }); diff --git a/test/integration/node-specific/bson-options/use_bigint_64.test.ts b/test/integration/node-specific/bson-options/use_bigint_64.test.ts index e4cc2d4241d..6c6714351ab 100644 --- a/test/integration/node-specific/bson-options/use_bigint_64.test.ts +++ b/test/integration/node-specific/bson-options/use_bigint_64.test.ts @@ -15,17 +15,9 @@ describe('useBigInt64 option', function () { let coll: Collection; afterEach(async function () { - if (client) { - if (coll) { - await coll.drop().catch(() => null); - } - - if (db) { - await db.dropDatabase().catch(() => null); - } - - await client.close(); - } + await coll?.drop().catch(() => null); + await db?.dropDatabase().catch(() => null); + await client?.close(); }); describe('when not provided to client', function () { @@ -82,7 +74,7 @@ describe('useBigInt64 option', function () { client = await this.configuration.newClient().connect(); db = client.db(this.configuration.db, { useBigInt64: false }); - await db.dropCollection('useBigInt64Test').catch(() => null); + await db.dropCollection('useBigInt64Test'); coll = await db.createCollection('useBigInt64Test', { useBigInt64: true }); }); @@ -98,7 +90,7 @@ describe('useBigInt64 option', function () { beforeEach(async function () { client = await this.configuration.newClient().connect(); db = client.db(this.configuration.db); - await db.dropCollection('useBigInt64Test').catch(() => null); + await db.dropCollection('useBigInt64Test'); }); it('supercedes collection level when set to false at operation level', async function () { @@ -117,7 +109,7 @@ describe('useBigInt64 option', function () { beforeEach(async function () { client = await this.configuration.newClient().connect(); db = client.db(this.configuration.db); - await db.dropCollection('useBigInt64Test').catch(() => null); + await db.dropCollection('useBigInt64Test'); }); it('supercedes collection level when set to true at operation level', async function () { @@ -137,7 +129,7 @@ describe('useBigInt64 option', function () { client = await this.configuration.newClient({}, { useBigInt64: true }).connect(); db = client.db(this.configuration.db); - await db.dropCollection('useBigInt64Test').catch(() => null); + await db.dropCollection('useBigInt64Test'); coll = await db.createCollection('useBigInt64Test'); await coll.insertOne({ a: new BSON.Long(1) }); diff --git a/test/integration/node-specific/cursor_stream.test.js b/test/integration/node-specific/cursor_stream.test.js index 76353b5d0f3..3b06c5de57e 100644 --- a/test/integration/node-specific/cursor_stream.test.js +++ b/test/integration/node-specific/cursor_stream.test.js @@ -223,8 +223,8 @@ describe('Cursor Streams', function () { const collection = db.collection('streaming'); const updateCollection = db.collection('update_within_streaming'); - await collection.drop().catch(() => null); - await updateCollection.drop().catch(() => null); + await collection.drop(); + await updateCollection.drop(); const docs = Array.from({ length: 10 }, (_, i) => ({ _id: i, diff --git a/test/integration/node-specific/mongo_client.test.ts b/test/integration/node-specific/mongo_client.test.ts index e8578d17b9a..87889efa21a 100644 --- a/test/integration/node-specific/mongo_client.test.ts +++ b/test/integration/node-specific/mongo_client.test.ts @@ -716,7 +716,7 @@ describe('class MongoClient', function () { beforeEach(async function () { client = this.configuration.newClient(); collection = client.db('activeCursors').collection('activeCursors'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany(Array.from({ length: 50 }, (_, _id) => ({ _id }))); kills.length = 0; @@ -980,7 +980,7 @@ describe('class MongoClient', function () { beforeEach(async () => { collection = client.db('test').collection('activeCursors'); - await collection.drop().catch(() => null); + await collection.drop(); await collection.insertMany(Array.from({ length: 50 }, (_, _id) => ({ _id }))); kills.length = 0; diff --git a/test/integration/objectid.test.ts b/test/integration/objectid.test.ts index 82f489b5658..ac1c68ecda2 100644 --- a/test/integration/objectid.test.ts +++ b/test/integration/objectid.test.ts @@ -91,7 +91,7 @@ describe('ObjectId', function () { const oid3 = new ObjectId(); const collection = client.db().collection<{ _id: ObjectId }>('oid_range'); - await collection.drop().catch(() => null); + await collection.drop(); // Insertion intentionally out of order, we want to filter out 3 with a range query await collection.insertMany([{ _id: oid1 }, { _id: oid3 }, { _id: oid2 }]); diff --git a/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts b/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts index 3e751e2e3b2..ca0576d218a 100644 --- a/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts +++ b/test/integration/retryable-reads/retryable_reads.spec.prose.test.ts @@ -36,7 +36,7 @@ describe('Retryable Reads Spec Prose', () => { ); testCollection = client.db('retryable-reads-prose').collection('pool-clear-retry'); - await testCollection.drop().catch(() => null); + await testCollection.drop(); await testCollection.insertMany([{ test: 1 }, { test: 2 }]); // 2. Enable the following failpoint: diff --git a/test/integration/retryable-writes/retryable_writes.spec.prose.test.ts b/test/integration/retryable-writes/retryable_writes.spec.prose.test.ts index c1754b29b07..22f475978d0 100644 --- a/test/integration/retryable-writes/retryable_writes.spec.prose.test.ts +++ b/test/integration/retryable-writes/retryable_writes.spec.prose.test.ts @@ -100,7 +100,7 @@ describe('Retryable Writes Spec Prose', () => { ); testCollection = client.db('retryable-writes-prose').collection('pool-clear-retry'); - await testCollection.drop().catch(() => null); + await testCollection.drop(); // ii. Enable the following failpoint: // NOTE: "ix. Disable the failpoint" is done in afterEach diff --git a/test/integration/sessions/sessions.prose.test.ts b/test/integration/sessions/sessions.prose.test.ts index 824430109f3..759faaa7901 100644 --- a/test/integration/sessions/sessions.prose.test.ts +++ b/test/integration/sessions/sessions.prose.test.ts @@ -71,7 +71,7 @@ describe('Sessions Prose Tests', () => { // reset test collection testCollection = client.db('test').collection('too.many.sessions'); - await testCollection.drop().catch(() => null); + await testCollection.drop(); }); afterEach(async () => { diff --git a/test/integration/sessions/sessions.test.ts b/test/integration/sessions/sessions.test.ts index f05426ccda6..92c0198f696 100644 --- a/test/integration/sessions/sessions.test.ts +++ b/test/integration/sessions/sessions.test.ts @@ -386,7 +386,7 @@ describe('Sessions Spec', function () { .connect(); // reset test collection testCollection = utilClient.db('test').collection('too.many.sessions'); - await testCollection.drop().catch(() => null); + await testCollection.drop(); await utilClient.close(); // Fresh unused client for the test diff --git a/test/integration/shared.js b/test/integration/shared.js index 5019e4fad9c..426af22df27 100644 --- a/test/integration/shared.js +++ b/test/integration/shared.js @@ -39,7 +39,7 @@ function delay(timeout) { } function dropCollection(dbObj, collectionName, options = {}) { - return dbObj.dropCollection(collectionName, options).catch(ignoreNsNotFound); + return dbObj.dropCollection(collectionName, options); } /** @@ -86,10 +86,6 @@ function filterOutCommands(commands, bag) { }; } -function ignoreNsNotFound(err) { - if (!err.message.match(/ns not found/)) throw err; -} - async function setupDatabase(configuration, dbsToClean) { dbsToClean = Array.isArray(dbsToClean) ? dbsToClean : []; const configDbName = configuration.db; @@ -204,7 +200,6 @@ module.exports = { dropCollection, filterForCommands, filterOutCommands, - ignoreNsNotFound, setupDatabase, withCursor, APMEventCollector diff --git a/test/tools/spec-runner/index.js b/test/tools/spec-runner/index.js index 4807c2620be..40d02fe4c36 100644 --- a/test/tools/spec-runner/index.js +++ b/test/tools/spec-runner/index.js @@ -283,26 +283,16 @@ function prepareDatabaseForSuite(suite, context) { } return coll.drop(options); }) - .catch(err => { - if (!err.message.match(/ns not found/)) throw err; - }) .then(() => { if (suite.key_vault_data) { const dataKeysCollection = context.sharedClient.db('keyvault').collection('datakeys'); - return dataKeysCollection - .drop({ writeConcern: { w: 'majority' } }) - .catch(err => { - if (!err.message.match(/ns not found/)) { - throw err; - } - }) - .then(() => { - if (suite.key_vault_data.length) { - return dataKeysCollection.insertMany(suite.key_vault_data, { - writeConcern: { w: 'majority' } - }); - } - }); + return dataKeysCollection.drop({ writeConcern: { w: 'majority' } }).then(() => { + if (suite.key_vault_data.length) { + return dataKeysCollection.insertMany(suite.key_vault_data, { + writeConcern: { w: 'majority' } + }); + } + }); } }) .then(() => { @@ -698,11 +688,7 @@ const kOperations = new Map([ const collectionName = operation.arguments.collection; const encryptedFields = operation.arguments.encryptedFields; const session = maybeSession(operation, context); - return db.dropCollection(collectionName, { session, encryptedFields }).catch(err => { - if (!err.message.match(/ns not found/)) { - throw err; - } - }); + return db.dropCollection(collectionName, { session, encryptedFields }); } ], [ diff --git a/test/tools/unified-spec-runner/operations.ts b/test/tools/unified-spec-runner/operations.ts index d208d49fc89..2e87b099ae9 100644 --- a/test/tools/unified-spec-runner/operations.ts +++ b/test/tools/unified-spec-runner/operations.ts @@ -310,15 +310,7 @@ operations.set('dropCollection', async ({ entities, operation }) => { const db = entities.getEntity('db', operation.object); const { collection, ...opts } = operation.arguments!; - // TODO(NODE-4243): dropCollection should suppress namespace not found errors - try { - await db.dropCollection(collection, opts); - } catch (err) { - if (!/ns not found/.test(err.message)) { - throw err; - } - return false; - } + return await db.dropCollection(collection, opts); }); operations.set('drop', async ({ entities, operation }) => {