Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2638

DBRef drops additional fields during serialization

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • bson-4.13.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None

      When deserializing a hash which contains a  $ref  field, thus producing a DBRef, if there are additional fields other than $ref/$id/$db those are dropped from the DBRef object and subsequently aren't serialized back.

       

      The extended json spec says additional fields are permitted.

       

      
       irb(main):007:0> e={'$ref'=>'x','$id'=>123,'x'=>42}
      => {"$ref"=>"x", "$id"=>123, "x"=>42}
      irb(main):008:0> Hash.from_bson(BSON::ByteBuffer.new(e.to_bson.to_s))
      => #<Mongo::DBRef:0x000055f8a0ff04a8 @collection="x", @id=123, @database=nil>
      irb(main):009:0> Hash.from_bson(BSON::ByteBuffer.new(e.to_bson.to_s)).to_json
      => "{\"$ref\":\"x\",\"$id\":123}"
      irb(main):010:0> Hash.from_bson(BSON::ByteBuffer.new(e.to_bson.to_s)).as_json
      => {"$ref"=>"x", "$id"=>123}
      

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

              Created:
              Updated:
              Resolved: