一、激活數據庫分片功能數據庫
mongos> db.runCommand( { enablesharding : "test" } )
二、指定分片建對集合分片,範圍片鍵--建立索引spa
mongos> use test mongos> db.vast.ensureIndex( { id: 1 } ) mongos> use admin mongos> db.runCommand( { shardcollection : "test.vast",key : {id: 1} } )
三、集合分片驗證code
mongos> use test mongos> for(i=0;i<20000;i++){ db.vast1.insert({"id":i,"name":"clsn","age":70,"date":new Date()}); } mongos> db.vast.stats()