-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: bson-4.3.0
-
Component/s: BSON
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
When using #fetch method to retrieve a value of a Bson::Document with a symbol, an error is raised telling that the key was not found, but when using #[] with symbol it works.
irb(main):041:0> doc
=> {"name"=>"Joe", "age"=>33}
irb(main):042:0> doc[:name]
=> "Joe"
irb(main):043:0> doc.fetch('name')
=> "Joe"
irb(main):044:0> doc.fetch(:name)
Traceback (most recent call last):
3: from /Users/jmolina/.rbenv/versions/2.5.1/bin/irb:11:in `<main>'
2: from (irb):44
1: from (irb):44:in `fetch'
KeyError (key not found: :name)
Because of this restriction, we cannot use #fetch in our classes to protect us from having nil values, instead we will have to check every key and return an error if it does not exists.
- causes
-
RUBY-1677 BSON::Document#fetch does not conform to Hash#fetch API
-
- Closed
-