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

Bson::Document#fetch does not work with symbols

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.4.1
    • Affects Version/s: bson-4.3.0
    • Component/s: BSON
    • 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.

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            jmolina91 Javier Molina Sánchez
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: