cannot create an index and its reverse

XMLWordPrintableJSON

    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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 Jordan
              Reporter:
              David De Sousa
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: