MongoDB Finishing Notes Management sharding

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.