Values for BSON::Binary fields are not converted to Binary

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • 8.0.1
    • Affects Version/s: None
    • Component/s: Attributes
    • Major Change
    • None
    • None
    • None
    • None
    • None
    • None

      When a field declared as a BSON::Binary is assigned a string value, this value remains as a string and appears to be persisted as a string:

      class MyModel
        include Mongoid::Document
      
        field :data,      type: BSON::Binary
      end
      
      irb(main):010:0> m = MyModel.new(data: 'test')
      => #<MyModel _id: 5df15c8b026d7c381b150ea4, data: "test">
      irb(main):011:0> m.save!
      => true
      irb(main):012:0> m = MyModel.find(m.id)
      => #<MyModel _id: 5df15c8b026d7c381b150ea4, data: "test">
      irb(main):013:0> m
      => #<MyModel _id: 5df15c8b026d7c381b150ea4, data: "test">
      

      One would expect that the string would be converted to a BSON::Binary instance when the attribute is set in the model originally, then stored as a Binary.

            Assignee:
            Neil Shweky (Inactive)
            Reporter:
            Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: