[SERVER-37907] Sharding a collection with invalid options displays a misleading error Created: 02/Nov/18  Updated: 06/Dec/22  Resolved: 05/Nov/18

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 3.6.8, 4.0.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Danny Hatcher (Inactive) Assignee: [DO NOT USE] Backlog - Sharding Team
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-37908 Improve the interface of `sh.shardCol... Closed
Related
Assigned Teams:
Sharding
Operating System: ALL
Steps To Reproduce:
  1. Launch a sharded cluster
  2.  sh.enableSharding("test") 

  3.  sh.shardCollection("test.foo", {_id:"hashed"}, {pieinthesky:1}) 

  4. Error appears that is not indicative of the true problem
Participants:

 Description   

When sharding a collection with a hashed shard key but including invalid options will output the following error:

mongos> sh.shardCollection("test.foo", {_id:"hashed"}, {pieinthesky:1})
{
	"ok" : 0,
	"errmsg" : "Hashed shard keys cannot be declared unique. It's possible to ensure uniqueness on the hashed field by declaring an additional (non-hashed) unique index on the field.",
	"code" : 72,
	"codeName" : "InvalidOptions",
	"operationTime" : Timestamp(1541185291, 4),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1541185291, 4),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}

The problem is my invalid option, not the hashed shard key.



 Comments   
Comment by Danny Hatcher (Inactive) [ 05/Nov/18 ]

Duplicates SERVER-37908 as the root issue is that the unique parameter (despite being optional) is required if options are specified.

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