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

Collection#with allows incorrect options to be changed

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      In the Collection#with method, only 4 options are allowed to get changed:

      Unable to find source-code formatter for language: ruby. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      CHANGEABLE_OPTIONS = [ :read, :read_concern, :write, :write_concern ]
      

      Now, write is a deprecated option that is equivalent to write_concern, and I think whoever wrote these options believed that read is a deprecated option equivalent to read_concern. Unfortunately, it seems that this is not true. I have found that whenever read is used, the mode option is used, which is a read_preference option. Additionally I found the following docstring:

      Unable to find source-code formatter for language: ruby. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      # @option options [ Hash ] :read The read preference options. The hash
      #   may have the following items:
      #   - *:mode* -- read preference specified as a symbol; valid values are
      #     *:primary*, *:primary_preferred*, *:secondary*, *:secondary_preferred*
      #     and *:nearest*.
      #   - *:tag_sets* -- an array of hashes.
      #   - *:local_threshold*.
      

      which pretty explicitly states that read is a read preference option.

      Additionally this code snipped implies that read and read_preference are equivalent: https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/collection.rb#L168-L170

      The docstring for #with also says the following:

      Provides a new collection with either a new read preference or new write concern merged over the existing read preference / write concern.

      So the CHANGEABLE_OPTIONS are clearly wrong, and the read_concern should be replaced with read_preference.

            Assignee:
            Unassigned Unassigned
            Reporter:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: