1、激活数据库分片功能
mongos> db.runCommand( { enablesharding : "test" } )
2、指定分片建对集合分片,范围片键--创建索引
mongos> use test mongos> db.vast.ensureIndex( { id: 1 } ) mongos> use admin mongos> db.runCommand( { shardcollection : "test.vast",key : {id: 1} } )
3、集合分片验证
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()