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

"Wrapper to skip query evolution" should evolve values in a field-independent manner

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      MONGOID-5408 proposes to add a "Wrapper to skip evolution while querying".

      As a refinement to this ticket, the wrapper should evolve values so they are compatible with the Mongo Ruby Driver, however, the evolution should be done in a field-independent manner.

      Known cases where this is useful:

      1. BigDecimal "raw values" should evolve to BSON::Decimal128.
      2. Range values should mongoize (not evolve) to their { min: 1, max: 3 } form.
      3. Array / Hash should recursively evolve to cover BigDecimal / Range members.

      In most cases evolve returns the same object (Integer -> Integer, String -> String, etc.) so the implementation should probably evolve all raw values.

      To illustrate how this works, consider the example:

       

      class Person
        field :name, as: String
        field :age,  as: Integer
      end
      
      Person.where(name: Mongoid::RawValue(BigDecimal(42)))
        #=> This should query for name: 42 as BSON::Decimal128
        #   Note that the field type String is ignored.
      
      Person.where(age: 20..30)
        #=> This queries for age $gte: 20, $lte: 30.
        #   (This is the existing behavior)
      
      Person.where(age: Mongoid::RawValue(20..30))
        #=> this queries for age equals the Hash literal { min: 20, max: 30 } 

       

       

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

              Created:
              Updated:
              Resolved: