{"record":{"id":"0f7a99788ce8e5fb","repo":"Automattic/mongoose","slug":"cannot-set-returnoriginal-when-returndocument","errorCode":null,"errorMessage":"Cannot set `returnOriginal` when `returnDocument` is already set. Use `returnDocument` instead.","messagePattern":"Cannot set `returnOriginal` when `returnDocument` is already set\\. Use `returnDocument` instead\\.","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/mongoose.js","lineNumber":327,"sourceCode":"        delete _mongoose.Types.ObjectId.prototype._id;\n      }\n    } else if (optionKey === 'transactionAsyncLocalStorage') {\n      if (optionValue && !_mongoose.transactionAsyncLocalStorage) {\n        _mongoose.transactionAsyncLocalStorage = new AsyncLocalStorage();\n      } else if (!optionValue && _mongoose.transactionAsyncLocalStorage) {\n        delete _mongoose.transactionAsyncLocalStorage;\n      }\n    } else if (optionKey === 'createInitialConnection') {\n      if (optionValue && !_mongoose.connection) {\n        _createDefaultConnection(_mongoose);\n      } else if (optionValue === false && _mongoose.connection?.[defaultConnectionSymbol]) {\n        if (_mongoose.connection.readyState === STATES.disconnected && utils.hasOwnKeys(_mongoose.connection.models) === false) {\n          _mongoose.connections.shift();\n        }\n      }\n    } else if (optionKey === 'returnOriginal') {\n      if (_mongoose.options.returnDocument != null) {\n        throw new MongooseError(\n          'Cannot set `returnOriginal` when `returnDocument` is already set. Use `returnDocument` instead.'\n        );\n      }\n      const replacement = optionValue === true ? '\\'before\\'' : '\\'after\\'';\n      utils.warn(\n        'Mongoose: the `returnOriginal` option for `mongoose.set()` is deprecated. ' +\n        'Use `mongoose.set(\\'returnDocument\\', ' + replacement + ')` instead.'\n      );\n    } else if (optionKey === 'returnDocument') {\n      if (_mongoose.options.returnOriginal != null) {\n        throw new MongooseError(\n          'Cannot set `returnDocument` when `returnOriginal` is already set. Use `returnDocument` instead of `returnOriginal`.'\n        );\n      }\n    }\n  }\n\n  if (error) {","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/mongoose.js#L309-L345","documentation":"Error \"Cannot set `returnOriginal` when `returnDocument` is already set. Use `returnDocument` instead.\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/mongoose.js:327 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"}