Automattic/mongoose · error · MongooseError

Cannot set `returnDocument` when `returnOriginal` is already

Error message

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

What it means

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

Source

Thrown at lib/mongoose.js:338

      } 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) {
    throw error;
  }

  return _mongoose;
};

/**
 * Gets mongoose options
 *
 * #### Example:
 *

View on GitHub (pinned to 49cdab0136)

When it happens

Trigger: Thrown at lib/mongoose.js:338 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/805cb9fb7fb082bb. Report an issue: GitHub.