Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5293

Add Rails-style defaults & `config.load_defaults.`

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible

      Problem Statement

      Mongoid 7.4 introduced feature flags, which is a very positive step. However:

      Problem #1: currently, in order to upgrade to upgrade and just get the latest bug fixes, I have to add all the following to my initializer:

        Mongoid.legacy_triple_equals  = false
        Mongoid.object_id_as_json_oid = false
        Mongoid.compare_time_by_ms    = true
        Mongoid.broken_aggregables    = false
        Mongoid.broken_updates        = false
        Mongoid.broken_and            = false
        Mongoid.broken_scoping        = false
        Mongoid.broken_alias_handling = false
        Mongoid.legacy_pluck_distinct = false 

      Its quite a burden to manage 10 configs, ensure values are correct, etc., and if I have to do the same in 7.5, 7.6 etc. my config will quickly become unmanageable.

      Problem #2: Consider for new users of Mongoid, if they install version 7.4, then out-of-the-box they are exposed to the ~10 or so "broken" behaviors above, unless they know to copy/paste all the feature flags above (which newbies are probably unaware.)

      Proposed Fix

      Rails has a very good way of doing feature flagging that solves both problems, and which is widely accepted in the Ruby community:

      {{}}

        config.load_defaults 7.0

      The default values of the config are set by this parameter. To give a Mongoid example, in the most recent 7.4 release, ideally, I should be able to set `load_defaults 7.4` and get all the feature flags above are switched on (feature flags off is done by `load_defaults 7.3`).

      When later I upgrade to 8.0, my config will already have `load_defaults 7.4`, so at that point I can just install the gem and be confident that nothing is breaking. (Upgrading to 8.0 might disallow load_defaults 7.3 or earlier, i.e. I have to already be on 7.4 in order to upgrade.)

      This is a bit of change so should be introduced in a major version, but I think the sooner it can be introduced the better for users.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: