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

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

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

      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@mongodb.com Neil Shweky (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: