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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 8.0.1
    • Attributes
    • Major Change

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              neil.shweky@mongodb.com Neil Shweky (Inactive)
              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: