-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 7.1.7, 7.0.12
-
Component/s: Attributes
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.
- is related to
-
MONGOID-4823 Values for BSON::Binary fields are not converted to Binary
- Closed
-
MONGOID-5335 Verify all fields store values in the declared type
- Backlog
- related to
-
MONGOID-4666 Allow Regexp fields to be set to nil
- Closed