1. 程式人生 > >MongoDB 學習筆記之 手動預先分片

MongoDB 學習筆記之 手動預先分片

var http strong str 可見 mongod 手動 ++ 1-1

手動預先分片:

目的:手動預先分片是為了防止未來chunk的移動,減少IO。

sh.shardCollection("shop.users",{"userId": 1 })

for(var i=1; i<=30; i++){ sh.splitAt("shop.users", {userId: i*1000}) }

技術分享

插入數據進行驗證:

for(var i=1; i<30000; i++){ db.users.insert({userId: i,name: ‘hello‘}) }

技術分享

技術分享

技術分享

由上可見,數據被均勻的分配在不同shard上。

MongoDB 學習筆記之 手動預先分片