{"record":{"id":"e73577516a844701","repo":"Automattic/mongoose","slug":"connection-prototype-dropdatabase-no-longer-acce","errorCode":null,"errorMessage":"Connection.prototype.dropDatabase() no longer accepts a callback","messagePattern":"Connection\\.prototype\\.dropDatabase\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/connection.js","lineNumber":939,"sourceCode":"\n/**\n * Helper for `dropDatabase()`. Deletes the given database, including all\n * collections, documents, and indexes.\n *\n * #### Example:\n *\n *     const conn = mongoose.createConnection('mongodb://127.0.0.1:27017/mydb');\n *     // Deletes the entire 'mydb' database\n *     await conn.dropDatabase();\n *\n * @method dropDatabase\n * @return {Promise}\n * @api public\n */\n\nConnection.prototype.dropDatabase = async function dropDatabase() {\n  if (arguments.length >= 1 && typeof arguments[0] === 'function') {\n    throw new MongooseError('Connection.prototype.dropDatabase() no longer accepts a callback');\n  }\n\n  await this._waitForConnect();\n\n  // If `dropDatabase()` is called, this model's collection will not be\n  // init-ed. It is sufficiently common to call `dropDatabase()` after\n  // `mongoose.connect()` but before creating models that we want to\n  // support this. See gh-6796\n  for (const model of Object.values(this.models)) {\n    delete model.$init;\n  }\n\n  return this.db.dropDatabase();\n};\n\n/*!\n * ignore\n */","sourceCodeStart":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/connection.js#L921-L957","documentation":"Mongoose 7 removed callback support; dropDatabase() is async and returns a Promise that resolves after the entire database (collections, documents, indexes) is deleted. Because the method takes no options, a function as the FIRST argument is treated as a removed callback and the method rejects immediately (lib/connection.js:939). Models stay compiled — only the data is dropped.","triggerScenarios":"conn.dropDatabase((err) => { ... }) — a function as the only argument.","commonSituations":"Test-suite reset helpers (beforeEach/beforeAll) written against mongoose 6 or earlier; upgrading to mongoose 7/8/9 without rewriting teardown code.","solutions":["Remove the callback and await: await conn.dropDatabase()","In test hooks: beforeEach(async () => { await conn.dropDatabase(); })"],"exampleFix":"// before\nconn.dropDatabase((err) => { done(err); });\n\n// after\nawait conn.dropDatabase();","handlingStrategy":"validation","validationCode":"function dropDatabaseSafe(...args) {\n  if (args.some(a => typeof a === 'function')) {\n    throw new TypeError('dropDatabase takes no callback — await the promise');\n  }\n  return conn.dropDatabase();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rewrite test reset hooks as async beforeEach/afterEach with await","Run a repo-wide search for `, (err` and `(err =>` near lifecycle calls when upgrading","Prefer deleteMany({}) or dropCollection over dropDatabase where possible to limit blast radius"],"tags":["dropdatabase","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"}