[SERVER-38367] Descriptive error message for the inability to create unique indexes on arbitrary fields in sharded collections Created: 03/Dec/18  Updated: 29/Oct/23  Resolved: 10/May/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.1.12

Type: Improvement Priority: Major - P3
Reporter: Alyson Cabral (Inactive) Assignee: Esha Maharishi (Inactive)
Resolution: Fixed Votes: 0
Labels: sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-38686 [createIndex response format] mongos ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Sharding 2019-01-14, Sharding 2019-01-28, Sharding 2019-02-11, Sharding 2019-02-25, Sharding 2019-05-06, Sharding 2019-05-20
Participants:

 Description   

When creating a unique index on a collection and not every shard has a chunk of the collection, the error "request doesn't allow collection to be created implicitly" will supersede the unique index error message.
Create index on a sharded collection with 1 chunk on shard A and no chunks on shard B:
 

mongos> db.bar.createIndex( { z: 1 }, { unique: true });
{
	"ok" : 0,
	"errmsg" : "request doesn't allow collection to be created implicitly",
	"code" : 227,
	"codeName" : "CannotImplicitlyCreateCollection",
	"ns" : "test.bar",
	"operationTime" : Timestamp(1543854707, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1543854707, 41),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}

Create index on a sharded collection with 1 chunk on shard A and 1 chunk on shard B:

mongos> db.foo.createIndex( { z: 1}, { unique: true } )
{
	"raw" : {
		"shardA/Kays-MacBook-Pro-2.local:27018,Kays-MacBook-Pro-2.local:27019,Kays-MacBook-Pro-2.local:27020" : {
			"ok" : 0,
			"errmsg" : "cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }",
			"code" : 67,
			"codeName" : "CannotCreateIndex"
		},
		"shardB/Kays-MacBook-Pro-2.local:27021,Kays-MacBook-Pro-2.local:27022,Kays-MacBook-Pro-2.local:27023" : {
			"ok" : 0,
			"errmsg" : "cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }",
			"code" : 67,
			"codeName" : "CannotCreateIndex"
		}
	},
	"code" : 67,
	"codeName" : "CannotCreateIndex",
	"ok" : 0,
	"errmsg" : "{ shardA/Kays-MacBook-Pro-2.local:27018,Kays-MacBook-Pro-2.local:27019,Kays-MacBook-Pro-2.local:27020: \"cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }\", shardB/Kays-MacBook-Pro-2.local:27021,Kays-MacBook-Pro-2.local:27022,Kays-MacBook-Pro-2.local:27023: \"cannot create unique index over { z: 1.0 } with shard key pattern { _id: 1.0 }\" }",
	"operationTime" : Timestamp(1543854778, 2),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1543854778, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}



 Comments   
Comment by Githook User [ 10/May/19 ]

Author:

{'email': 'esha.maharishi@mongodb.com', 'name': 'Esha Maharishi', 'username': 'EshaMaharishi'}

Message: SERVER-38367 Descriptive error message for the inability to create unique indexes on arbitrary fields in sharded collections
Branch: master
https://github.com/mongodb/mongo/commit/242deee7c584613d0cd8f5bc9e10eea73bd18aad

Generated at Thu Feb 08 04:48:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.