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

DBRef can be created without $id

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

      Per jmikola , if a hash that contains $ref but not $id is deserialized , it produces a DBRef that has a nil $id:

       

      
       irb(main):004:0> b={'$ref'=>'x'}
      => {"$ref"=>"x"}
      irb(main):005:0> Hash.from_bson(BSON::ByteBuffer.new(b.to_bson.to_s))
      => #<Mongo::DBRef:0x000055f8a0fd8ec0 @collection="x", @id=nil, @database=nil>
      irb(main):006:0> Hash.from_bson(BSON::ByteBuffer.new(b.to_bson.to_s)).as_json
      => {"$ref"=>"x", "$id"=>nil}
      
      
      Note the $id field is also added where there wasn't one previously.

            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: