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

Create unique index on colleciton with hashed sharding key

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.4
    • Affects Version/s: 2.4.6
    • Component/s: Index Maintenance
    • Labels:
      None
    • Environment:
      Ubuntu 12.04.x LTS
      3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
    • ALL
    • Hide

      create a collection with index

      {targetId : 1 ,timestamp: -1}, {unique : true}

      shard collection with with key

      { targetId: "hashed"}

      drop index

      {targetId : 1 ,timestamp: -1}

      try to recreate index

       {targetId : 1 ,timestamp: -1}, {unique : true}
      Show
      create a collection with index {targetId : 1 ,timestamp: -1}, {unique : true} shard collection with with key { targetId: "hashed"} drop index {targetId : 1 ,timestamp: -1} try to recreate index {targetId : 1 ,timestamp: -1}, {unique : true}

      We want to creat a compound index in a sharded collection with a hashed sharding key.

      The non hashed shard key is a prefix of the compound index.

      If we create the index before we shard the collection, mongodb does not complain about the index.

      {
      	"err" : "can't use unique indexes with sharding  ns:test.collection key: { targetId: 1.0, timestamp: -1.0 }",
      	"code" : 10205,
      	"n" : 0,
      	"ok" : 1
      }
      

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            steffen Steffen
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: