{"record":{"id":"d5bd55aab3aab09a","repo":"Automattic/mongoose","slug":"must-specify-model-in-connection-prototype-bulkwri","errorCode":null,"errorMessage":"Must specify model in Connection.prototype.bulkWrite() operations","messagePattern":"Must specify model in Connection\\.prototype\\.bulkWrite\\(\\) operations","errorType":"validation","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/connection.js","lineNumber":473,"sourceCode":"\nConnection.prototype.bulkWrite = async function bulkWrite(ops, options) {\n  await this._waitForConnect();\n  options = options || {};\n\n  const ordered = options.ordered == null ? true : options.ordered;\n  const asyncLocalStorage = this.base.transactionAsyncLocalStorage?.getStore();\n  if ((!options || !Object.hasOwn(options, 'session')) && asyncLocalStorage?.session != null) {\n    options = { ...options, session: asyncLocalStorage.session };\n  }\n\n  const now = this.base.now();\n\n  let res = null;\n  if (ordered) {\n    const opsToSend = [];\n    for (const op of ops) {\n      if (typeof op.model !== 'string' && !op.model?.[modelSymbol]) {\n        throw new MongooseError('Must specify model in Connection.prototype.bulkWrite() operations');\n      }\n      const Model = op.model[modelSymbol] ? op.model : this.model(op.model);\n\n      if (op.name == null) {\n        throw new MongooseError('Must specify operation name in Connection.prototype.bulkWrite()');\n      }\n      if (!Object.hasOwn(castBulkWrite.cast, op.name)) {\n        throw new MongooseError(`Unrecognized bulkWrite() operation name ${op.name}`);\n      }\n\n      await castBulkWrite.cast[op.name](Model, op, options, now);\n      opsToSend.push({ ...op, namespace: Model.namespace() });\n    }\n\n    res = await this.client.bulkWrite(opsToSend, options);\n  } else {\n    const validOps = [];\n    const validOpIndexes = [];","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/connection.js#L455-L491","documentation":"Error \"Must specify model in Connection.prototype.bulkWrite() operations\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/connection.js:473 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"}