Automattic/mongoose · error · MongooseError
Connection.prototype.dropCollection() no longer accepts a…
Error message
Connection.prototype.dropCollection() no longer accepts a callback
What it means
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.
Solutions
- Remove the callback and await: await conn.dropCollection('users')
- Move the old callback body into try/catch around the awaited call
Example fix
// before
conn.dropCollection('users', (err) => { done(err); });
// after
await conn.dropCollection('users'); Defensive patterns
Strategy: validation
Validate before calling
function dropCollectionSafe(name) {
if (typeof name !== 'string') {
throw new TypeError('dropCollection expects a collection name string');
}
return conn.dropCollection(name);
} Type guard
const isCollectionName = (v) => typeof v === 'string' && v.length > 0;
Prevention
- 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
When it happens
Trigger: conn.dropCollection('users', (err) => { ... }) — a collection name followed by a callback function.
Common situations: 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.
Related errors
- Connection.prototype.close() no longer accepts a callback
- Connection.prototype.destroy() no longer accepts a callback
- Connection.prototype.dropDatabase() no longer accepts a…
- Connection.prototype.openUri() no longer accepts a callback
- Connection.prototype.startSession() no longer accepts a…
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/06741011d95ec233.
Report an issue: GitHub.
Appendix: source
Thrown at lib/connection.js:811
}
val[arrayAtomicsSymbol] = state.atomics.get(path);
}
}
}
/**
* Helper for `dropCollection()`. Will delete the given collection, including
* all documents and indexes.
*
* @method dropCollection
* @param {string} collection The collection to delete
* @return {Promise}
* @api public
*/
Connection.prototype.dropCollection = async function dropCollection(collection) {
if (arguments.length >= 2 && typeof arguments[1] === 'function') {
throw new MongooseError('Connection.prototype.dropCollection() no longer accepts a callback');
}
await this._waitForConnect();
return this.db.dropCollection(collection);
};
/**
* Waits for connection to be established, so the connection has a `client`
*
* @param {boolean} [noTimeout=false] if set, don't put a timeout on the operation. Used internally so `mongoose.model()` doesn't leave open handles.
* @return {Promise}
* @api private
*/
Connection.prototype._waitForConnect = async function _waitForConnect(noTimeout) {
if ((this.readyState === STATES.connecting || this.readyState === STATES.disconnected) && this._shouldBufferCommands()) {
const bufferTimeoutMS = this._getBufferTimeoutMS();View on GitHub (pinned to 49cdab0136)