|
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?
|