当我在进行分片时,在mongodb中使用addShard函数时出现以下错误: 请帮帮我
"ok" : 0,
"errmsg" : "no such command: addShard",
"code" : 59,
"bad cmd" : {
"addShard" : "<server name>"
}
为什么会出现此错误?
答案 0 :(得分:1)
看起来你可能没有连接到mongos实例。
确保您已连接到mongos(路由器)。下面是我用来实现分片的代码示例,参考addShard。为了彻底,我将剩余的代码包括在内。
//this adds members of a replica set as a shard
sh.addShard("rs0/serverShd4:27017,serverShd4b:27017,serverShd4c:27017")
//indexes
use mydb
db.mycoll.ensureIndex({s:"hashed"})
//The db name is "mydb"
sh.enableSharding("mydb")
//This is the shard key strategy deemed necessary by OI to date
sh.shardCollection( "mydb.mycoll", { s: "hashed" } )
答案 1 :(得分:0)
切换到db admin
db.runCommand({addshard:“localhost:10000”})
{“shardadded”:“shard0000”,“ok”:1}
db.runCommand({addshard:“localhost:10001”})
{“shardadded”:“shard0001”,“ok”:1}
应该有效。 http://comments.gmane.org/gmane.comp.db.mongodb.user/77102