Thursday, April 3, 2014

MongoDB 2.4 - sharding

- killall mongod
- killall mongos
- cd
- mkdir a0, b0, cfg0
- mongod --shardsvr --dbpath a0 --logpath log.a0 --fork --logappend --smallfiles --oplogSize 50
- Note that with --shardsvr specified the default port for mongod becomes 27018
- mongod --configsvr --dbpath cfg0 --fork --logpath log.cfg0 --logappend
- Note with --configsvr specified the default port for listening becomes 27019 and the default data directory /data/configdb. Wherever your data directory is, it is suggested that you verify that the directory is empty before you begin.
- mongos --configdb your_host_name:27019 --fork --logappend --logpath log.mongos0
- mongo
- sh.addShard('your_host_name:27018')
- sh.enableSharding('databaseName')
- db.collectionName.ensureIndex({a:1,b:1})
- sh.shardCollection('databaseName.collectionName',{a:1,b:1})
- use config
- db.chunks.find()
- db.chunks.find({}, {min:1,max:1,shard:1,_id:0,ns:1})
- exit
- mongod --shardsvr --dbpath b0 --logpath log.b0 --fork --logappend --smallfiles --oplogSize 50 --port 27000
- mongo
- sh.addShard('your_host_name:27000')
- sh.status()
- db.getSisterDB("config").shards.count()

Mongo 2.4.9 - currentOp and killOp

- db.currentOp()

...
"opid" : 20165
...

- db.killOp(20165)