MongoDB Introductory tutorials in the slicing technology detailed _MONGODB

Source: Internet
Author: User
Tags mongodb

There is another cluster in the MongoDB, the partitioning technology, similar to the table partitioning of SQL Server, we know that when the amount of data reaches the T level, our disk, memory is too high, how to deal with such a scenario how we should respond.

One: Fragmentation

MongoDB a solution that splits the collection and then splits the split data into several slices.

Let me explain to this picture:

face: on behalf of the client, the client must say, you do not fragmented database fragmentation and I do not have to do what I tell you to do, nothing good to discuss.

MONGOs: First we have to understand the concept of "key", that is, what is the basis for splitting the collection? Divide the collection by what key value ....

Well, MONGOs is a routing server that will allocate data to its own managed Mongod cluster based on the "Slice key" set by the administrator, data

The corresponding relationship to the slice and the corresponding configuration information is saved on the config server.

Mongod: A common database example, if not fragmented, we will directly connect to the Mongod.

Two: Actual combat

First we prepare 4 MongoDB programs, I am here to split the c,d,e,f disk, of course you can also do multiple folder forms.

1: Config server open

Previously said, MONGOs to put the configuration between the Mongod on the config server, the first to open it, I will build 2222 ports here.

2: Open MONGOs Server

Note here that we are opening the MONGOs, not Mongod, and specify the next config server, here I will open the D disk on the MongoDB, Port 3333.

3: Start the Mongod server

For slicing, that is, to add a slice, here to open the E,f disk MongoDB, the port is: 4444,5555.

4: Service Configuration

Haha, is not very excited, but also the last point of the configuration we can do.

<1> in the previous image, we can see that the client directly deal with MONGOs, it means we have to connect the MONGOs server, and then 4444,5555 Mongod

To MONGOs, add a fragment is also Addshard ().

Note here that in Addshard, we can also add a replica set to achieve higher stability.

<2> has been clustered, but MONGOs do not know how to split the data, which is what we said before the key, in the MongoDB to set the key to do two steps

①: Open the database fragmentation function, the command is very simple enablesharding (), here I open the test database.

②: Specifies the slice key in the collection, which I specify as the Person.name field.

5: Viewing effects

Okay, so now that we're done with the Shard, we're going to insert a 10w record into MongoDB via MONGOs, and then we'll pass the Printshardingstatus command

View the MongoDB data fragmentation situation.

Here are mainly three points of information:

①shards: We clearly see that there are no more than two pieces, shard0000 and shard0001.

②databases: Here's a partitioned field for partitioning, and it's clear to see that test has been partitioned.

③chunks: This is interesting, we found that the collection was hacked into four sections:

Infinitely small--jack0,jack0--jack234813,jack234813--jack9999,jack9999--infinity.

The partitioning situation is: 3:1, from the back on Shardxxxx can also be seen.

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.