### To Start config server instance (config server port: 27019)
mongod.exe --configsvr --dbpath ../../configdb --port 27019
### To start mongos instance (router) (router port: 27017)
mongos.exe --configdb localhost:27019
###Adding a shard
First start mongoDb instance
mongod.exe --config ../../mongo.cfg
mongod.exe --config ../../mongo1.cfg
Config file content:
##store data here
dbpath=C:\poc\mdb\data
##all output go here
logpath=C:\poc\mdb\log\mongo.log
##log read and write operations
##diaglog=3
###Auth detail admin/admin
auth=false
##Port binding
port=27020
###Open a new instance and add above mongodb instance in cluster:
mongo.exe --host localhost --port 27017
once mongos console connected:
sh.addShard("localhost:27020")
sh.addShard("localhost:27021")
sh.enableSharding("ankur")
use config
db.databases.find()
###Insert bulk data
for (var i = 1; i <= 1000; i++) db.test_collection.insert( { x : i } )
###To know the shard status
sh.status()
###To shard a collection
sh.shardCollection("ankur.records",{"zip":1, "name":1})
###Data insertion
{
db.records.insert( { zip : 60111 , name: "ankur"})
db.records.insert( { zip : 60111 , name: "goel"})
db.records.insert( { zip : 50111 , name: "ankur"})
db.records.insert( { zip : 50111 , name: "goel"})
db.records.insert( { zip : 70111 , name: "dr"})
}
###To know chunk distribution
db.records.getShardDistribution()
Source: http://docs.mongodb.org/manual/reference/method/#sharding
No comments:
Post a Comment