Automattic/mongoose · error

MONGOOSE

MONGOOSE

Error message

Mongoose: the `returnOriginal` option for `mongoose.set()` is deprecated. Use `mongoose.set('returnDocument', ${replacement})` instead.

What it means

Error "Mongoose: the `returnOriginal` option for `mongoose.set()` is deprecated. Use `mongoose.set('returnDocument', ${replacement})` instead." thrown in Automattic/mongoose.

Source

Thrown at lib/mongoose.js:332

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

  return _mongoose;
};

View on GitHub (pinned to 49cdab0136)

When it happens

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