Automattic/mongoose · error · MongooseError

Connection.prototype.createCollection() no longer accepts a

Error message

Connection.prototype.createCollection() no longer accepts a callback

What it means

Error "Connection.prototype.createCollection() no longer accepts a callback" thrown in Automattic/mongoose.

Source

Thrown at lib/connection.js:424

Connection.prototype.config;

/**
 * Helper for `createCollection()`. Will explicitly create the given collection
 * with specified options. Used to create [capped collections](https://www.mongodb.com/docs/manual/core/capped-collections/)
 * and [views](https://www.mongodb.com/docs/manual/core/views/) from mongoose.
 *
 * Options are passed down without modification to the [MongoDB driver's `createCollection()` function](https://mongodb.github.io/node-mongodb-native/7.0/classes/Db.html#createCollection)
 *
 * @method createCollection
 * @param {string} collection The collection to create
 * @param {object} [options] see [MongoDB driver docs](https://mongodb.github.io/node-mongodb-native/7.0/classes/Db.html#createCollection)
 * @return {Promise}
 * @api public
 */

Connection.prototype.createCollection = async function createCollection(collection, options) {
  if (typeof options === 'function' || (arguments.length >= 3 && typeof arguments[2] === 'function')) {
    throw new MongooseError('Connection.prototype.createCollection() no longer accepts a callback');
  }

  await this._waitForConnect();

  return this.db.createCollection(collection, options);
};

/**
 * _Requires MongoDB Server 8.0 or greater_. Executes bulk write operations across multiple models in a single operation.
 * You must specify the `model` for each operation: Mongoose will use `model` for casting and validation, as well as
 * determining which collection to apply the operation to.
 *
 * #### Example:
 *     const Test = mongoose.model('Test', new Schema({ name: String }));
 *
 *     await db.bulkWrite([
 *       { model: Test, name: 'insertOne', document: { name: 'test1' } }, // Can specify model as a Model class...
 *       { model: 'Test', name: 'insertOne', document: { name: 'test2' } } // or as a model name

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/connection.js:424 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21). Data as JSON: /api/errors/46138c0b3f9f61c1. Report an issue: GitHub.