连接mongos端口使用该sh.enableSharding()方法在目标数据库上启用分片。在数据库上启用分片可以在数据库中分片集合。
mongos端口
sh.enableSharding()
sh.enableSharding("<database>")
从mongo连接到的shell中mongos,使用该sh.shardCollection()方法对集合进行分片。
mongo
mongos
sh.shardCollection()
注意
您必须已为集合所在的数据库启用了分片。
如果集合已包含数据,则必须在使用之前使用该方法在分片键上创建索引 。db.collection.createIndex()shardCollection()
db.collection.createIndex()
shardCollection()
如果集合为空,MongoDB将创建索引作为其中的一部分 sh.shardCollection()。