Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-7578

Enforcing Unique Keys for Sharded Collections not accurate.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Last comment by Customer:
      true
    • Story Points:
      2.5

      Description

      The documentation states
      "MongoDB does not support creating new unique indexes in sharded collections and will not allow you to shard collections with unique indexes on fields other than the _id field."

      But I can do:

      MongoDB Enterprise mongos> db.testColUniq5.insert({"email":"a"})
      WriteResult({ "nInserted" : 1 })
      MongoDB Enterprise mongos> db.testColUniq5.createIndex({"email":1},{unique:1})
      {
      	"raw" : {
      		"Shakirs-MacBook-Pro.local:27018" : {
      			"createdCollectionAutomatically" : false,
      			"numIndexesBefore" : 1,
      			"numIndexesAfter" : 2,
      			"ok" : 1
      		}
      	},
      	"ok" : 1
      }
      MongoDB Enterprise mongos> sh.shardCollection("test.testColUniq5", {"email":1},{unique:true})
      { "collectionsharded" : "test.testColUniq5", "ok" : 1 }
      MongoDB Enterprise mongos> 
      

      Further... it states I should not be able to create new unique indexes BUT I can and it's broken:

      MongoDB Enterprise mongos> db.testColUniq5.createIndex({"email3":1},{unique:1})
      {
      	"raw" : {
      		"Shakirs-MacBook-Pro.local:27018" : {
      			"createdCollectionAutomatically" : false,
      			"numIndexesBefore" : 2,
      			"ok" : 0,
      			"errmsg" : "cannot create unique index over { email3: 1.0 } with shard key pattern { email: 1.0 }",
      			"code" : 67
      		},
      		"Shakirs-MacBook-Pro.local:27019" : {
      			"createdCollectionAutomatically" : false,
      			"numIndexesBefore" : 2,
      			"numIndexesAfter" : 3,
      			"ok" : 1
      		},
      		"Shakirs-MacBook-Pro.local:27020" : {
      			"createdCollectionAutomatically" : false,
      			"numIndexesBefore" : 2,
      			"numIndexesAfter" : 3,
      			"ok" : 1
      		}
      	},
      	"code" : 67,
      	"ok" : 0,
      	"errmsg" : "{ Shakirs-MacBook-Pro.local:27018: \"cannot create unique index over { email3: 1.0 } with shard key pattern { email: 1.0 }\" }"
      }
      

      Further, if you go to the individual shards, 2 of 3 actually have the new unique index added. Is this a bug?

        Attachments

          Activity

            People

            Assignee:
            ravind.kumar Ravind Kumar (Inactive)
            Reporter:
            shakir.sadikali Shakir Sadikali
            Participants:
            Last commenter:
            Kay Kim Kay Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Days since reply:
              5 years, 24 weeks, 2 days ago
              Date of 1st Reply: