[DOCS-7578] Enforcing Unique Keys for Sharded Collections not accurate. Created: 05/Apr/16  Updated: 30/Oct/23  Resolved: 16/Mar/23

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Shakir Sadikali Assignee: Ravind Kumar (Inactive)
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 46 weeks, 6 days ago
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?



 Comments   
Comment by Sarah Olson [ 16/Mar/23 ]

Closing this out on the grounds that:

  • Details of this request are significantly outdated. 
  • Our documentation has evolved substantially since this request was made. 

Based on this, closing as WON'T DO. Please don't hesitate to give me a shout or to reopen if you disagree.

Generated at Thu Feb 08 07:54:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.