1.I'm running shard server
./mongod --shardsvr --dbpath /data/r1/ --port 10000
2.Configuration server
./mongod --configsvr --dbpath /data/db/config/ --port 20000
3.mongos server
./mongos --configdb localhost:20000 --port 30000
4.client
./mongo localhost:30000/admin
Here I'm creating collection table and insert with 1 key called
"name"
db.table1.find();
and then i performing these steps to add and enable sharding
> db.runCommand(
{ addshard : "localhost:10000" });
{ "shardAdded" : "shard0000", "ok" : 1 }> db.runCommand(
{ enablesharding : "admin" })
{ "ok" : 1 }>db.table1.ensureIndex(
{ name: 1 });
> db.runCommand( { shardcollection : "admin.table1",key :
{name : 1},unique:true });
{ "collectionsharded" : "admin.table1", "ok" : 1 }>db.printShardingStatus()
— Sharding Status —
sharding version:
shards:
{ "_id" : "shard0000", "host" : "localhost:10000" }databases:
{ "_id" : "admin", "partitioned" : true, "primary" : "config" } admin.table1 chunks:
{ "name" :
} -->> { "name" :
{ $maxKey : 1 } } on :
config
when i want to see the collection items it's showing like this
> db.table1.find();
error: