MongoDB Data Partition Maintenance

Source: Internet
Author: User

Reprinted from http://www.cnblogs.com/spnt/

The sharding maintenance of MongoDB is also about the several commands, which are relatively simple. We will use the example for demonstration.

1. List all shard servers

Note that you need to connect to the admin of the route. Parameter 1 of listshards is a fixed default value and has no special meaning.

2. View sharding information.

Switch to the friends database and use printshardingstatus () to view the current sharding information.

3. Execute sharding on the existing table.

We have performed sharding on the frienduserattach table above. Next we are doing sharding on another table named frienduser.

First, check the frienduser status.

The first row sharded = false indicates that the table is not sharded. Then we connect to the admin of the vro and execute the sharding command.

Sharding is performed on the database's frids table frienduser. The partition key is _ id. Run the command to check the status.

You can see that the parts have been successfully split.

4. added the shard server.

The new shard server is useless. This is a command that will certainly be used in big data. The steps are as follows:

First, start a new MongoDB with the port number set to 2002.

Add this new process to the prepared "string". Note: This is to be connected to the admin of the route.

Next, let's take a look at the current shard situation.

A shard0002 multipart is added.

5. Remove parts.

Removing a part is not implemented immediately. He needs to transfer the data on the part to another part. After the transfer is completed, the part will be officially kicked off. At this time, you also need to call the command multiple times to check that the removal operation is executed there.

The removal command is dB. runcommand ({"removeshard": "IP + port"}). Note that you need to use the admin database to perform the operation.

Here we can see the status clearly:

Started: the removal action has just begun.

Ongoing: removing ongoing

Completed: Completed

The last prompt "can't find shard" indicates that the server has been kicked out and taken offline.

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.