{"record":{"id":"46138c0b3f9f61c1","repo":"Automattic/mongoose","slug":"connection-prototype-createcollection-no-longer","errorCode":null,"errorMessage":"Connection.prototype.createCollection() no longer accepts a callback","messagePattern":"Connection\\.prototype\\.createCollection\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/connection.js","lineNumber":424,"sourceCode":"Connection.prototype.config;\n\n/**\n * Helper for `createCollection()`. Will explicitly create the given collection\n * with specified options. Used to create [capped collections](https://www.mongodb.com/docs/manual/core/capped-collections/)\n * and [views](https://www.mongodb.com/docs/manual/core/views/) from mongoose.\n *\n * 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)\n *\n * @method createCollection\n * @param {string} collection The collection to create\n * @param {object} [options] see [MongoDB driver docs](https://mongodb.github.io/node-mongodb-native/7.0/classes/Db.html#createCollection)\n * @return {Promise}\n * @api public\n */\n\nConnection.prototype.createCollection = async function createCollection(collection, options) {\n  if (typeof options === 'function' || (arguments.length >= 3 && typeof arguments[2] === 'function')) {\n    throw new MongooseError('Connection.prototype.createCollection() no longer accepts a callback');\n  }\n\n  await this._waitForConnect();\n\n  return this.db.createCollection(collection, options);\n};\n\n/**\n * _Requires MongoDB Server 8.0 or greater_. Executes bulk write operations across multiple models in a single operation.\n * You must specify the `model` for each operation: Mongoose will use `model` for casting and validation, as well as\n * determining which collection to apply the operation to.\n *\n * #### Example:\n *     const Test = mongoose.model('Test', new Schema({ name: String }));\n *\n *     await db.bulkWrite([\n *       { model: Test, name: 'insertOne', document: { name: 'test1' } }, // Can specify model as a Model class...\n *       { model: 'Test', name: 'insertOne', document: { name: 'test2' } } // or as a model name","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/connection.js#L406-L442","documentation":"Error \"Connection.prototype.createCollection() no longer accepts a callback\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/connection.js:424 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}