-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: 2.4.0-rc0
-
Component/s: None
-
None
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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.