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

BSON::Regexp::Raw not serialized to a regex when field type is specified as String

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.1.1, 5.2.1
    • Affects Version/s: None
    • Component/s: None
    • None

      If a field type is specified as String, a BSON::Regexp::Raw query criteria will be converted to a String, instead of to a regex.

      For example:

      class Band
        include Mongoid::Document
        field :_id, type: String
      end
      > Band.where(_id: Regexp::Raw.new('^5:1480505452050829690_2035751180-')).limit(-1)
      => #<Mongoid::Criteria
        selector: {"_id"=>"#<BSON::Regexp::Raw:0x007f92e8bc70c8>"}
        options:  {:limit=>-1}
        class:    Band
        embedded: false>
      

      It should be:

      Band.where(_id: Regexp::Raw.new('^5:1480505452050829690_2035751180-')).limit(-1)
      => #<Mongoid::Criteria
        selector: {"_id"=>#<BSON::Regexp::Raw:0x007fc6441678c8 @pattern="^5:1480505452050829690_2035751180-", @options="">}
        options:  {:limit=>-1}
        class:    Band
        embedded: false>
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            emily.stolfo Emily Stolfo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: