@@ -458,6 +458,64 @@ for details on driver options.
458458 # methods. (default: false, driver version: 2.18.0+)
459459 #validate_update_replace: false
460460
461+
462+ .. _load-defaults:
463+
464+ Version Based Defaults
465+ ======================
466+
467+ Mongoid supports setting the configuration options to the defaults for specific
468+ versions. This is useful for upgrading to a new Mongoid version. When upgrading
469+ your Mongoid version, the following should be set on ``Mongoid::Config``:
470+
471+ .. code:: ruby
472+
473+ Mongoid.configure do |config|
474+ config.load_defaults <OLD VERSION>
475+ end
476+
477+ This way, when upgrading to a new version of Mongoid, your code will run with
478+ the configuration options from the previous version of Mongoid. Then,
479+ one-by-one, you can change the feature flags for the new version, and test that
480+ your code still acts as expected. Once all of the new feature flags have been
481+ accounted for, the call to ``load_defaults`` can be changed to take in the *new*
482+ version, and all of the changed feature flags can be removed. For example, say
483+ we're upgrading from 7.5 to 8.0. Between these two versions, only two feature
484+ flags were added: ``legacy_attributes`` and ``map_big_decimal_to_decimal128``.
485+ Before upgrading to Mongoid 8, the following line can be added:
486+
487+ .. code:: ruby
488+
489+ Mongoid.configure do |config|
490+ config.load_defaults 7.5
491+ end
492+
493+ Now, after upgrading, those two feature flags will default to their 7.5
494+ functionality (``legacy_attributes: true, map_big_decimal_to_decimal128: false``).
495+ Now you can set these feature flags one-by-one and flip them to their 8.0
496+ behavior:
497+
498+ .. code:: ruby
499+
500+ Mongoid.configure do |config|
501+ config.load_defaults 7.5
502+ config.legacy_attributes = false
503+ # config.map_big_decimal_to_decimal128 = true
504+ end
505+
506+ It is advised to do these one at a time, so I have left the second flag
507+ commented out. After verifying your code works as expected with the
508+ ``legacy_attributes`` flag turned off, the ``map_big_decimal_to_decimal128``
509+ setting can be uncommented. Once that functionality is verified as well, both
510+ of those lines can be removed and the ``load_defaults`` replaced with:
511+
512+ .. code:: ruby
513+
514+ Mongoid.configure do |config|
515+ config.load_defaults 8.0
516+ end
517+
518+
461519ERb Preprocessing
462520=================
463521
0 commit comments