我测试sharding时提示出错如上,不过我是给id加过索引呀。
for(var i=1;i<=10;i++) db.users_hash.insert({_id:i,name:"tao"+i,addr:"BeiJing"});
db.collection.createIndex( { _id: "hashed" } )
db.users_hash.getIndexKeys()
sh.shardCollection("testshard.users_hash", { "_id": "hashed" } )
北京-梦里香 2015/12/23 14:25:03
mongos> sh.shardCollection("testshard.users_hash", { "_id": "hashed" } )
{
"proposedKey" : {
"_id" : "hashed"
},
"curIndexes" : [
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "testshard.users_hash"
}
],
"ok" : 0,
"errmsg" : "please create an index that starts with the shard key before sharding."
for(var i=1;i<=10;i++) db.users_hash.insert({_id:i,name:"tao"+i,addr:"BeiJing"});
db.collection.createIndex( { _id: "hashed" } )
db.users_hash.getIndexKeys()
sh.shardCollection("testshard.users_hash", { "_id": "hashed" } )
北京-梦里香 2015/12/23 14:25:03
mongos> sh.shardCollection("testshard.users_hash", { "_id": "hashed" } )
{
"proposedKey" : {
"_id" : "hashed"
},
"curIndexes" : [
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "testshard.users_hash"
}
],
"ok" : 0,
"errmsg" : "please create an index that starts with the shard key before sharding."









