Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5827

Index not get creating

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 9.1.0, 9.0.7, 8.1.11
    • Affects Version/s: None
    • Component/s: Persistence
    • None
    • Fully Compatible
    • Ruby Drivers
    • Needed
    • Hide

      *NOTE: * this ticket has been updated and the changes were backported to the 9.0 and 8.1 branches, to be released (eventually) in 9.0.7 and 8.1.11.

      1. What would you like to communicate to the user about this feature?

      We've added a new configuration option, Mongoid.allow_duplicate_index_declarations. It defaults to false (which is the legacy behavior). When it is false, Mongoid attempts to detect when a duplicate index is declared on a model, and (silently) ignores it. This has caused problems in the past when Mongoid incorrectly identifies an index as a duplicate.

      To work around this problem, you can set the above flag to true, which will pass all index declarations to the server. If the server detects a duplicate index declaration, it will raise an error.

      When we eventually release Mongoid 10.0, we will change this flag so it defaults to true, and will phase the flag out entirely by Mongoid 11.0.

      2. Would you like the user to see examples of the syntax and/or executable code and its output?

      Not necessary.

      3. Which versions of the driver/connector does this apply to?

      Mongoid 9.1.0, 9.0.7, and 8.1.11 (all of which are unreleased, as of this writing).

      Show
      *NOTE: * this ticket has been updated and the changes were backported to the 9.0 and 8.1 branches, to be released (eventually) in 9.0.7 and 8.1.11. 1. What would you like to communicate to the user about this feature? We've added a new configuration option, Mongoid.allow_duplicate_index_declarations . It defaults to false (which is the legacy behavior). When it is false, Mongoid attempts to detect when a duplicate index is declared on a model, and (silently) ignores it. This has caused problems in the past when Mongoid incorrectly identifies an index as a duplicate. To work around this problem, you can set the above flag to true, which will pass all index declarations to the server. If the server detects a duplicate index declaration, it will raise an error. When we eventually release Mongoid 10.0, we will change this flag so it defaults to true, and will phase the flag out entirely by Mongoid 11.0. 2. Would you like the user to see examples of the syntax and/or executable code and its output? Not necessary. 3. Which versions of the driver/connector does this apply to? Mongoid 9.1.0, 9.0.7, and 8.1.11 (all of which are unreleased, as of this writing).
    • None
    • None
    • None
    • None
    • None
    • None

      When creating indexes that conflict (same keys different options) they are ignored. I would expect it to not be ignored if they have different names and raise an error if they have the same name but different options/keys.

      require 'mongoid'
      
      Mongoid.configure do |config|
        config.clients.default = { hosts: ['localhost:27017'], database: 'bugs' }
      end
      
      class Foo
        include Mongoid::Document
        field :bar, type: String
        field :baz, type: String
      
        index({ bar: 1 }, { partial_filter_expression: { baz: '1' } })
        index({ bar: 1 }, { name: 'partial_bar_2', partial_filter_expression: { baz: '2' } })
      end
      
      Foo.create_indexes
      # I expect 3, 1 for _id and 2 i just created
      raise 'index didnt get created!' if Foo.collection.indexes.count != 3
      
      class Foo2
        include Mongoid::Document
        field :bar, type: String
        field :baz, type: String
      
        index({ bar: 1 }, { partial_filter_expression: { baz: '1' } })
        index({ bar: 1 }, { partial_filter_expression: { baz: '2' } })
      end
      
      Foo2.create_indexes # I expiect it to raise an error
      

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            jonathag@cisco.com Jonathon Gardner
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 1 week
                1w
                Logged:
                Time Spent - Not Specified
                Not Specified