Automattic/mongoose · error · MongooseError

Cannot set `returnOriginal` when `returnDocument` is already

Error message

Cannot set `returnOriginal` when `returnDocument` is already set. Use `returnDocument` instead.

What it means

Error "Cannot set `returnOriginal` when `returnDocument` is already set. Use `returnDocument` instead." thrown in Automattic/mongoose.

Source

Thrown at lib/mongoose.js:327

        delete _mongoose.Types.ObjectId.prototype._id;
      }
    } else if (optionKey === 'transactionAsyncLocalStorage') {
      if (optionValue && !_mongoose.transactionAsyncLocalStorage) {
        _mongoose.transactionAsyncLocalStorage = new AsyncLocalStorage();
      } else if (!optionValue && _mongoose.transactionAsyncLocalStorage) {
        delete _mongoose.transactionAsyncLocalStorage;
      }
    } else if (optionKey === 'createInitialConnection') {
      if (optionValue && !_mongoose.connection) {
        _createDefaultConnection(_mongoose);
      } else if (optionValue === false && _mongoose.connection?.[defaultConnectionSymbol]) {
        if (_mongoose.connection.readyState === STATES.disconnected && utils.hasOwnKeys(_mongoose.connection.models) === false) {
          _mongoose.connections.shift();
        }
      }
    } else if (optionKey === 'returnOriginal') {
      if (_mongoose.options.returnDocument != null) {
        throw new MongooseError(
          'Cannot set `returnOriginal` when `returnDocument` is already set. Use `returnDocument` instead.'
        );
      }
      const replacement = optionValue === true ? '\'before\'' : '\'after\'';
      utils.warn(
        'Mongoose: the `returnOriginal` option for `mongoose.set()` is deprecated. ' +
        'Use `mongoose.set(\'returnDocument\', ' + replacement + ')` instead.'
      );
    } else if (optionKey === 'returnDocument') {
      if (_mongoose.options.returnOriginal != null) {
        throw new MongooseError(
          'Cannot set `returnDocument` when `returnOriginal` is already set. Use `returnDocument` instead of `returnOriginal`.'
        );
      }
    }
  }

  if (error) {

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/mongoose.js:327 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/0f7a99788ce8e5fb. Report an issue: GitHub.