Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-34841

Cannot create multiple indexes with the same pattern but different options

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • Index Maintenance
    • None
    • ALL

    Description

      Background:

      In our production system, we have an unique index, that used the wrong partialFilterExpression. This caused the query planner to not use this index when querying for documents.

      To fix this issue, we want to create the correct index, and only drop the previous index afterwards, to ensure we still have consistency.

      However, MongoDB prevents us from creating another index with the same pattern:

      // Old (wrong) index
      db.users.createIndex({"sessions._id": 1}, {name: 'session_id', unique: true, partialFilterExpression: {'sessions': {"$exists" : true}}})
       
      // New index
      db.users.createIndex({"sessions._id": 1}, {name: 'session_id2', unique: true, partialFilterExpression: {'sessions._id': {"$exists" : true}}})
       
      {{ "ok" : 0, "errmsg" : "Index with pattern: { sessions._id: 1.0 } already exists with different options", "code" : 85}
      
      

       

      Our only solution currently is to first drop the old index, then create the new one. However, this results in a period of time where the unique constraint is not enforced, which can potentially cause issues.

      This may be a duplicate of https://jira.mongodb.org/browse/SERVER-22194, but that issue had a different use case, and was closed as a duplicated of a different issue.

       

      Attachments

        Issue Links

          Activity

            People

              ramon.fernandez@mongodb.com Ramon Fernandez Marina
              ralf@embarkmobile.com Ralf Kistner
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: