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

cannot create an index and its reverse

      for example, having this class:

      class MyDocument
      include Mongoid::Document
      field :one_field, type: String
      field :another_field, type: String

      index(

      {one_field: 1, another_field: 1}

      )
      index(

      {another_field: 1, one_field: 1}

      )
      end

      will only create one index, this is because index_options is a hash that uses index() first parameter as key, so the second call to index() would update the same object.

      this is fixable by doing

      class MyDocument
      include Mongoid::Document
      field :one_field, type: String
      field :another_field, type: String

      index_options.compare_by_identity
      index(

      {one_field: 1, another_field: 1}

      )
      index(

      {another_field: 1, one_field: 1}

      )
      end

      that makes the index_option hash recognize both keys as different, maybe this should be enabled by default?

            Assignee:
            durran Durran Jordan
            Reporter:
            dedsm David De Sousa
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: