Automattic/mongoose · error · MongooseError
Connection.prototype.dropDatabase() no longer accepts a call
Error message
Connection.prototype.dropDatabase() no longer accepts a callback
What it means
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.
Source
Thrown at lib/connection.js:939
/**
* Helper for `dropDatabase()`. Deletes the given database, including all
* collections, documents, and indexes.
*
* #### Example:
*
* const conn = mongoose.createConnection('mongodb://127.0.0.1:27017/mydb');
* // Deletes the entire 'mydb' database
* await conn.dropDatabase();
*
* @method dropDatabase
* @return {Promise}
* @api public
*/
Connection.prototype.dropDatabase = async function dropDatabase() {
if (arguments.length >= 1 && typeof arguments[0] === 'function') {
throw new MongooseError('Connection.prototype.dropDatabase() no longer accepts a callback');
}
await this._waitForConnect();
// If `dropDatabase()` is called, this model's collection will not be
// init-ed. It is sufficiently common to call `dropDatabase()` after
// `mongoose.connect()` but before creating models that we want to
// support this. See gh-6796
for (const model of Object.values(this.models)) {
delete model.$init;
}
return this.db.dropDatabase();
};
/*!
* ignore
*/View on GitHub (pinned to 49cdab0136)
Solutions
- Remove the callback and await: await conn.dropDatabase()
- In test hooks: beforeEach(async () => { await conn.dropDatabase(); })
Example fix
// before
conn.dropDatabase((err) => { done(err); });
// after
await conn.dropDatabase(); Defensive patterns
Strategy: validation
Validate before calling
function dropDatabaseSafe(...args) {
if (args.some(a => typeof a === 'function')) {
throw new TypeError('dropDatabase takes no callback — await the promise');
}
return conn.dropDatabase();
} Prevention
- 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
When it happens
Trigger: conn.dropDatabase((err) => { ... }) — a function as the only argument.
Common situations: Test-suite reset helpers (beforeEach/beforeAll) written against mongoose 6 or earlier; upgrading to mongoose 7/8/9 without rewriting teardown code.
Related errors
- Connection.prototype.startSession() no longer accepts a call
- Connection.prototype.dropCollection() no longer accepts a ca
- Connection.prototype.openUri() no longer accepts a callback
- Connection.prototype.destroy() no longer accepts a callback
- Connection.prototype.close() no longer accepts a callback
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/e73577516a844701.
Report an issue: GitHub.