[SERVER-8687] Error messages when trying to shard on a 2dsphere index are incorrect. Created: 22/Feb/13  Updated: 11/Jul/16  Resolved: 12/Jun/13

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.4.0-rc0
Fix Version/s: 2.5.1

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Greg Studer
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 Description   

When trying to shard using a 2dsphere index the error message is not helpful:

mongos> sh.shardCollection('geo.geos2', {'geo': '2dsphere'})
{ "ok" : 0, "errmsg" : "unrecognized string: 2dsphere" }

The error message should tell you that sharding on a 2dsphere index is not allowed.

At the very least it should use the same message used when trying to shard on a compound key index including a 2dsphere field:

mongos> sh.shardCollection('geo.geos2', {'_id': 1, 'geo': '2dsphere'})
{
	"ok" : 0,
	"errmsg" : "Unsupported shard key pattern.  Pattern must either be a single hashed field, or a list of ascending fields."
}

We should also give a hint to users that try to shard on a 2dsphere index without specifying '2dsphere' in the key. For example:

mongos> db.geos2.ensureIndex({'geo': '2dsphere'})
mongos> sh.shardCollection('geo.geos2', {'geo': 1})
{
	"proposedKey" : {
		"geo" : 1
	},
	"curIndexes" : [
		{
			"v" : 1,
			"key" : {
				"_id" : 1
			},
			"ns" : "geo.geos2",
			"name" : "_id_"
		},
		{
			"v" : 1,
			"key" : {
				"geo" : "2dsphere"
			},
			"ns" : "geo.geos2",
			"name" : "geo_2dsphere"
		}
	],
	"ok" : 0,
	"errmsg" : "please create an index that starts with the shard key before sharding."
}

Since we know the geo field has a 2dsphere index on it we could give a better warning.



 Comments   
Comment by auto [ 12/Jun/13 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-9859 SERVER-8687 prevent hashed sharding w/o default seed
Branch: master
https://github.com/mongodb/mongo/commit/1e03edb5a6432018af994e1f41e359ae903493a9

Generated at Thu Feb 08 03:18:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.