{"record":{"id":"8ccc4b3bd8a8e925","repo":"Automattic/mongoose","slug":"model-create-no-longer-accepts-a-callback","errorCode":null,"errorMessage":"Model.create() no longer accepts a callback","messagePattern":"Model\\.create\\(\\) no longer accepts a callback","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/model.js","lineNumber":2692,"sourceCode":" *     await Character.create([{ name: 'Will Riker' }, { name: 'Geordi LaForge' }]);\n *\n *     // Create a new character within a transaction. Note that you **must**\n *     // pass an array as the first parameter to `create()` if you want to\n *     // specify options.\n *     await Character.create([{ name: 'Jean-Luc Picard' }], { session });\n *\n * @param {Array|object} docs Documents to insert, as a spread or array\n * @param {object} [options] Options passed down to `save()`. To specify `options`, `docs` **must** be an array, not a spread. See [Model.save](https://mongoosejs.com/docs/api/model.html#Model.prototype.save()) for available options.\n * @param {boolean} [options.ordered] saves the docs in series rather than parallel.\n * @param {boolean} [options.aggregateErrors] Aggregate Errors instead of throwing the first one that occurs. Default: false\n * @return {Promise}\n * @api public\n */\n\nModel.create = async function create(doc, options) {\n  if (typeof options === 'function' ||\n      typeof arguments[2] === 'function') {\n    throw new MongooseError('Model.create() no longer accepts a callback');\n  }\n\n  _checkContext(this, 'create');\n\n  let args;\n  const discriminatorKey = this.schema.options.discriminatorKey;\n\n  if (Array.isArray(doc)) {\n    args = doc;\n    options = options != null && typeof options === 'object' ? options : {};\n  } else {\n    const last = arguments[arguments.length - 1];\n    options = {};\n    const hasCallback = typeof last === 'function' ||\n      typeof options === 'function' ||\n      typeof arguments[2] === 'function';\n    if (hasCallback) {\n      throw new MongooseError('Model.create() no longer accepts a callback');","sourceCodeStart":2674,"sourceCodeEnd":2710,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/model.js#L2674-L2710","documentation":"Model.create() became an async function that only accepts documents plus an options object; Mongoose 7 removed callback support. This first guard throws when options itself is a function or the third argument is a function, i.e. the array form Model.create([docs], callback) or Model.create(doc, callback) where the callback lands in the options parameter. Because create() is async, the throw surfaces as a rejected promise rather than a synchronous throw.","triggerScenarios":"Calling Model.create([d1, d2], cb) (array plus callback), or Model.create(doc, cb) where cb occupies the options slot (arguments[1]), or passing any function as arguments[2].","commonSituations":"Mongoose 6 to 7/8 upgrades; bulk-seed scripts written with callbacks; generic factory helpers that append a done() function to create() calls.","solutions":["Use await: const docs = await Model.create([d1, d2]); or const doc = await Model.create(d1); with try/catch","Remember options must be an object and only allowed when docs is an array: await Model.create([d1, d2], { session, ordered: true })","Audit the codebase for create(..., function/arrow) patterns during the Mongoose 7 migration","Pin mongoose@6 as a temporary stopgap","Use TypeScript: the create() signature no longer accepts a callback, so tsc flags it"],"exampleFix":"// before\nUser.create([{ name: 'a' }], (err, docs) => { ... });\n\n// after\nconst docs = await User.create([{ name: 'a' }]);","handlingStrategy":"validation","validationCode":"function createSafe(Model, docs, options) {\n  if (typeof options === 'function') throw new TypeError('create(): pass options object, not a callback');\n  if (arguments.length > 3) throw new TypeError('create(): extra argument');\n  return Model.create(docs, options);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const docs = await Model.create(list, { session, ordered: true });\n} catch (err) {\n  if (/no longer accepts a callback/.test(err.message)) { /* legacy call site: switch to await */ }\n  else throw err;\n}","preventionTips":["Remember create() only accepts options when docs is an array","Mocha/jest: never pass done() as the last create() argument","Use TypeScript; the promise-only signature rejects callback forms"],"tags":["mongoose","callback","promise","migration","api-change","create"],"backgroundTag":"callback-to-promise-migration","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}