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

Strings assigned to Regexp fields get stored/retrieved as strings

      Even though there appears to be a method mongoizing strings into regexps (https://jira.mongodb.org/browse/MONGOID-4666), assigning a string value to a regexp field persists the string in the database and the value is retrieved back as a string:

      irb(main):074:0> class Foo; include Mongoid::Document; field :x, type: Regexp; end
      Overwriting existing field x in class Foo.
      => #<Mongoid::Fields::Standard:0x0000563c886b2518 @name="x", @options={:type=>Mongoid::Matchable::Regexp, :klass=>Foo}, @label=nil, @default_val=nil>
      irb(main):075:0> a=Foo.new(x:'bar')
      => #<Foo _id: 5bff574c026d7c797db48d85, x: "bar">
      irb(main):076:0> a.save
      MONGODB | localhost:27101 | mongoid.insert | STARTED | {"insert"=>"foos", "ordered"=>true, "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x0000563c8707d928 @seconds=1543460461, @increment=1>, "signature"=>{"hash"=><BSON::Binary:0x47408981732340 type=generic data=0x0000000000000000...>, "keyId"=>0}}, "...
      MONGODB | localhost:27101 | mongoid.insert | SUCCEEDED | 0.001s
      => true
      irb(main):077:0> a=Foo.find(a.id)
      MONGODB | localhost:27101 | mongoid.find | STARTED | {"find"=>"foos", "filter"=>{"_id"=>BSON::ObjectId('5bff574c026d7c797db48d85')}, "$clusterTime"=>{"clusterTime"=>#<BSON::Timestamp:0x0000563c88679e70 @seconds=1543460686, @increment=1>, "signature"=>{"hash"=><BSON::Binary:0x47408993259180 type=generic ...
      MONGODB | localhost:27101 | mongoid.find | SUCCEEDED | 0.001s
      => #<Foo _id: 5bff574c026d7c797db48d85, x: "bar">
      irb(main):078:0> a.x
      => "bar"
      

      The value should be persisted and retrieved back as a regexp.

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: