4.5 开启数据库和集合分片(指定片键)
继续使用完成分片开启和分片大小设置
为数据库开启分片功能sh.enableSharding("rpp_resume")为指定集合开启分片功能sh.shardCollection("rpp_resume.rpp_resume_datas",{"name":"hashed"})
mongos> sh.enableSharding("rpp_resume"){"ok" : 1,"operationTime" : Timestamp(1602326356, 5),"$clusterTime" : {"clusterTime" : Timestamp(1602326356, 5),"signature" : {"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),"keyId" : NumberLong(0)}}}mongos> sh.shardCollection("rpp_resume.rpp_resume_datas",{"name":"hashed"}){"collectionsharded" : "rpp_resume.rpp_resume_datas","collectionUUID" : UUID("c4e62fd0-499e-420e-895a-4dbe8a66646f"),"ok" : 1,"operationTime" : Timestamp(1602326368, 30),"$clusterTime" : {"clusterTime" : Timestamp(1602326368, 30),"signature" : {"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),"keyId" : NumberLong(0)}}}mongos>
4.6 向集合中插入数据测试
通过路由循环向集合中添加数
userpp_resume;for(var i=1;i<= 1000;i++){db.rpp_resume_datas.insert({"name":"test"+i, salary:(Math.random()*20000).toFixed(2)});}
4.7 验证分片效果
分别进入和中的主从数据库进行验证
37017
shard1:PRIMARY> db.rpp_resume_datas.find(){ "_id" : ObjectId("5f818fa9d5fb279dbd7028f4"), "name" : "test3", "salary" : "415.41" }{ "_id" : ObjectId("5f818fa9d5fb279dbd7028f5"), "name" : "test4", "salary" : "567.00" }{ "_id" : ObjectId("5f818fa9d5fb279dbd7028f6"), "name" : "test5", "salary" : "5979.64" }{ "_id" : ObjectId("5f818fa9d5fb279dbd7028fa"), "name" : "test9", "salary" : "19307.87" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290a"), "name" : "test25", "salary" : "14712.60" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290b"), "name" : "test26", "salary" : "15679.53" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290c"), "name" : "test27", "salary" : "17134.48" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290d"), "name" : "test28", "salary" : "10127.22" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290e"), "name" : "test29", "salary" : "19221.05" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702910"), "name" : "test31", "salary" : "12848.60" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702911"), "name" : "test32", "salary" : "9617.72" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702914"), "name" : "test35", "salary" : "1220.32" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702915"), "name" : "test36", "salary" : "10541.12" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702916"), "name" : "test37", "salary" : "891.18" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702917"), "name" : "test38", "salary" : "16313.15" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70291a"), "name" : "test41", "salary" : "14766.15" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70291c"), "name" : "test43", "salary" : "15438.16" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702921"), "name" : "test48", "salary" : "1059.71" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702922"), "name" : "test49", "salary" : "648.91" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702924"), "name" : "test51", "salary" : "6677.53" }Type "it" for moreshard1:PRIMARY>
37018
shard1:SECONDARY> db.rpp_resume_datas.find(){ "_id" : ObjectId("5f818fa9d5fb279dbd7028f4"), "name" : "test3", "salary" : "415.41" }{ "_id" : ObjectId("5f818fa9d5fb279dbd7028f5"), "name" : "test4", "salary" : "567.00" }{ "_id" : ObjectId("5f818fa9d5fb279dbd7028f6"), "name" : "test5", "salary" : "5979.64" }{ "_id" : ObjectId("5f818fa9d5fb279dbd7028fa"), "name" : "test9", "salary" : "19307.87" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290a"), "name" : "test25", "salary" : "14712.60" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290b"), "name" : "test26", "salary" : "15679.53" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290c"), "name" : "test27", "salary" : "17134.48" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290d"), "name" : "test28", "salary" : "10127.22" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702910"), "name" : "test31", "salary" : "12848.60" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70290e"), "name" : "test29", "salary" : "19221.05" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702911"), "name" : "test32", "salary" : "9617.72" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702914"), "name" : "test35", "salary" : "1220.32" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702916"), "name" : "test37", "salary" : "891.18" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702915"), "name" : "test36", "salary" : "10541.12" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702917"), "name" : "test38", "salary" : "16313.15" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70291a"), "name" : "test41", "salary" : "14766.15" }{ "_id" : ObjectId("5f818fa9d5fb279dbd70291c"), "name" : "test43", "salary" : "15438.16" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702921"), "name" : "test48", "salary" : "1059.71" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702922"), "name" : "test49", "salary" : "648.91" }{ "_id" : ObjectId("5f818fa9d5fb279dbd702924"), "name" : "test51", "salary" : "6677.53" }Type "it" for moreshard1:SECONDARY>
- Mongodb的副本、分片搭建方式
- Redis缓存服务器的 分片机制 和 哨兵机制 的配置与详解
- 二 进击消息中间件系列:Kafka 单机与集群部署实践
- pycharm连接远程mysql_【已解决】用PyCharm的MongoDB插件
- 打造八大优势产业集群,长沙挺起先进制造“硬脊梁” 长沙之中国之最
- Rancher搭建K8S集群并配置GPU共享完整流程
- 乡村文化产业集群:乡村振兴新引擎,让农村发展更有魅力! 文化产业历史之最有哪些
- KingbaseES V8R6集群运维案例之---sys_rewind应用分析
- 一、查询openGauss集群状态
- RabbitMQ --- 惰性队列、MQ集群