1. List all shard servers
> Db.runcommand ({listshards:1})-- lists all shard server{"Shards" : [{"_id": "shard0000"," Host ":" localhost:20000 "},{" _id ":" shard0001 "," host ":" Localhost:20001 "}]," OK ": 1}
View Code
2. View sharding Information
> Printshardingstatus ()-- view sharding info ---sharding Status---sharding version: { "_id": 1, "version": 3}shards:{ "_id": "shard0000", " Host ":" localhost:20000 "" _id ":" shard0001 "," host ":" Localhost:20001 "}databases:{ "_id": "admin", "partitioned": false , "primary": "config" Span style= "color: #000000;" >} { "_id": "Test", "partitioned": true , "PRIMARY": "shard0000" }test.users chunks:shard0000 1{ "_id": {$minKey: 1}}-->> {"_id" : {$maxKey: 1 "T": +, "I": 0} ;
View Code
3, judge whether it is sharding
> Db.runcommand ({isdbgrid:1"Isdbgrid": 1, "hostname": "localhost", "OK": 1 }>
4. Shard the existing collection (instance)
Just now we have partitioned the table test.users, and we will fragment the existing non-fragmented table test.users_2 in the library.
The table initially states as follows, and it can be seen that he has not been fragmented:
>db.users_2.stats () {"NS": "Test.users_2","Sharded":false,"PRIMARY": "shard0000","NS": "Test.users_2","Count": 500000,"Size": 48000016,"Avgobjsize": 96.000032,"Storagesize": 61875968,"Numextents": 11,"Nindexes": 1,"Lastextentsize": 15001856,"Paddingfactor": 1,"Flags": 1,"Totalindexsize": 20807680,"Indexsizes" : {"_id_": 20807680},"OK": 1}
View Code
To fragment the process:
> Use adminswitched to DB admin> Db.runcommand ({shardcollection: "Test.users_2", key: {_id:1"Co Llectionsharded ":" Test.users_2 "," OK ": 1}
Once again, look at the state of the table after the Shard, and you can see that it's been sliced by us.
> Use testswitched to db Test> db.users_2.stats () {true,"ns": "Test.users_2" ,"Count": 505462,......" Shards " : {" shard0000 ": {" ns ":" Test.users_2 ",......" OK ": 1}," shard0001 " : {" ns ":" Test.users_2 ",......" OK ": 1}," OK ": 1}>
View Code
MongoDB Finishing Notes Management sharding