DBRef can be created without $id

XMLWordPrintableJSON

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

      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 (Inactive)
            Reporter:
            Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: