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

Client#initialize documentation is incorrect

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.0.5
    • Affects Version/s: 2.0.4
    • Component/s: Replica Set
    • Labels:
      None

      Client#initialize specifies that it accepts a :read option which takes a symbol value. However, the doc suggests a :mode key, which is in fact necessary, since the client throws an exception if you pass an unindexable value (such as a symbol) as your read preference.

      :read (Symbol) — The read preference options. :mode can be one of :secondary, :secondary_preferred, :primary, :primary_preferred, :nearest.

      > require 'mongo'
       => true
      > Mongo::Logger.logger = Logger.new("/dev/null")
       => #<Logger:0x7159139f @default_formatter=#<Logger::Formatter:0x65bcf7c2 @datetime_format=nil>, @progname=nil, @level=0, @formatter=nil, @logdev=#<Logger::LogDevice:0x3db64bd4 @shift_age=0, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x6e106680 @mon_mutex=#<Mutex:0x576c5536>, @mon_owner=nil, @mon_count=0>, @dev=#<File:/dev/null>, @shift_size=1048576, @filename="/dev/null">>
      > m = Mongo::Client.new ["localhost:27019"], connect: :replica_set, read: :secondary_preferred
       => #<Mongo::Client:0x2380 cluster=localhost:27019, luna:27019>
      > m["test"].find.limit(1).first
      TypeError: no implicit conversion of Symbol into Integer
              from org/jruby/RubyString.java:2898:in `[]'
              from org/jruby/RubySymbol.java:373:in `[]'
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/server_selector.rb:56:in `get'
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/client.rb:170:in `read_preference'
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/collection/view/readable.rb:318:in `default_read'
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/collection/view/readable.rb:251:in `read'
              from /usr/local/rvm/gems/jruby-head/gems/mongo-2.0.4/lib/mongo/collection/view/iterable.rb:38:in `each'
              from org/jruby/RubyEnumerable.java:397:in `first'
              from (irb):4:in `<eval>'
              from org/jruby/RubyKernel.java:980:in `eval'
              from org/jruby/RubyKernel.java:1293:in `loop'
              from org/jruby/RubyKernel.java:1100:in `catch'
              from org/jruby/RubyKernel.java:1100:in `catch'
              from /usr/local/rvm/rubies/jruby-head/bin/irb:13:in `<top>'
      

      Passing a hash with a :mode key works as expected:

       > m = Mongo::Client.new ["localhost:27019"], connect: :replica_set, read: {mode: :secondary_preferred}
       => #<Mongo::Client:0x2382 cluster=localhost:27019, luna:27019>
      > m["test"].find.limit(1).first
       => nil
      

      The documentation should be corrected to indicate that a hash is expected with a :mode key and an optional :tag_set key. Type checking on the value wouldn't be a bad idea, either.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            cheald Chris Heald
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: