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

Connect type in mongoid.yml is not applied because it's parsed as a String and a Symbol is expected

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.2
    • Affects Version/s: 2.4.1
    • Component/s: None
    • None
    • Environment:
      mac/linux, mongo 2.4.1/mongoid 6.0.3/5.1.2

      I believe there is an inconsistency between what you expect for the :connect and what is indicated in the doc for mongoid.

      In (mongo ruby) topology.rb, you have

            OPTIONS = {
              replica_set: ReplicaSet,
              sharded: Sharded,
              direct: Single
            }.freeze
      

      and

            def initial(seeds, monitoring, options)
              if options.has_key?(:connect)
                OPTIONS.fetch(options[:connect]).new(options, monitoring, seeds)
              elsif options.has_key?(:replica_set)
                ReplicaSet.new(options, monitoring, options)
              else
                Unknown.new(options, monitoring, seeds)
              end
            end
      

      On the other side, mongoid doc says that the yaml file can/should contain

      ...
              # Force the driver to connect in a specific way instead of auto-
              # discovering. Can be one of: :direct, :replica_set, :sharded. Set to :
              # when connecting to hidden members of a replica set.
              connect: :direct
      ...
      

      The issue is that :direct can/will be loaded as a string (after check, it probably depends on your YAML parser, but I haven't found any recommendations), and so will never be found in OPTIONS.
      Using HashWithIndifferentAccess means that you will get a connect (Symbol), but will not load its value (:direct) as a symbol. Symbolizing the value found will ensure that it's tested as a symbol. Having a default option for fetch might be also a nice touch, unsure though.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            sgareste Simon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: