{"record":{"id":"06741011d95ec233","repo":"Automattic/mongoose","slug":"connection-prototype-dropcollection-no-longer-ac","errorCode":null,"errorMessage":"Connection.prototype.dropCollection() no longer accepts a callback","messagePattern":"Connection\\.prototype\\.dropCollection\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/connection.js","lineNumber":811,"sourceCode":"      }\n      val[arrayAtomicsSymbol] = state.atomics.get(path);\n    }\n  }\n}\n\n/**\n * Helper for `dropCollection()`. Will delete the given collection, including\n * all documents and indexes.\n *\n * @method dropCollection\n * @param {string} collection The collection to delete\n * @return {Promise}\n * @api public\n */\n\nConnection.prototype.dropCollection = async function dropCollection(collection) {\n  if (arguments.length >= 2 && typeof arguments[1] === 'function') {\n    throw new MongooseError('Connection.prototype.dropCollection() no longer accepts a callback');\n  }\n\n  await this._waitForConnect();\n\n  return this.db.dropCollection(collection);\n};\n\n/**\n * Waits for connection to be established, so the connection has a `client`\n *\n * @param {boolean} [noTimeout=false] if set, don't put a timeout on the operation. Used internally so `mongoose.model()` doesn't leave open handles.\n * @return {Promise}\n * @api private\n */\n\nConnection.prototype._waitForConnect = async function _waitForConnect(noTimeout) {\n  if ((this.readyState === STATES.connecting || this.readyState === STATES.disconnected) && this._shouldBufferCommands()) {\n    const bufferTimeoutMS = this._getBufferTimeoutMS();","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/connection.js#L793-L829","documentation":"Mongoose 7 removed all callback-style APIs; dropCollection() is async and returns a Promise that resolves once the collection (documents and indexes) is deleted. A function in the second argument position (after the collection name) trips an explicit guard so legacy callback code fails loudly instead of the callback being silently dropped.","triggerScenarios":"conn.dropCollection('users', (err) => { ... }) — a collection name followed by a callback function.","commonSituations":"Test teardown helpers written against mongoose 6 or earlier; migrating an old suite to mongoose 7/8/9 without rewriting cleanup code; copied legacy snippets.","solutions":["Remove the callback and await: await conn.dropCollection('users')","Move the old callback body into try/catch around the awaited call"],"exampleFix":"// before\nconn.dropCollection('users', (err) => { done(err); });\n\n// after\nawait conn.dropCollection('users');","handlingStrategy":"validation","validationCode":"function dropCollectionSafe(name) {\n  if (typeof name !== 'string') {\n    throw new TypeError('dropCollection expects a collection name string');\n  }\n  return conn.dropCollection(name);\n}","typeGuard":"const isCollectionName = (v) => typeof v === 'string' && v.length > 0;","tryCatchPattern":null,"preventionTips":["Always await dropCollection and other connection helpers","When migrating from mongoose <= 6, sweep for two-argument calls","Keep teardown code promise-based from the start"],"tags":["dropcollection","callbacks","migration","mongoose-7"],"backgroundTag":"callback-api-removed","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}