MongoDB: mongodb sharding Technology

Source: Internet
Author: User
Tags mongodb sharding database sharding
MongoDB has another cluster technology, that is, MongoDB's sharding technology. I. MongoDB sharding MongoDB is a solution that splits a set and then distributes the split data to different slices. Next let's take a look at the structure: Face: representing the customer's access end mongos: the chip key is the basis for splitting, according to what kind of key value

MongoDB has another cluster technology, that is, MongoDB's sharding technology. I. MongoDB sharding MongoDB is a solution that splits a set and then distributes the split data to different slices. Next let's take a look at the structure: Face: representing the customer's access end mongos: the chip key is the basis for splitting, according to what kind of key value

MongoDB has another cluster technology, that is, MongoDB's sharding technology.

I. MongoDB sharding

MongoDB uses a solution to split a set and evenly distribute the split data to different slices.

The following figure shows the structure:

FACE: Representative of the customer's access end

Mongos: the "chip key" is the basis for sharding. What kind of key value is used for sharding... mongos is a vro that distributes data to the mongod cluster managed by the Administrator based on the "chip key, the correspondence between data and slices and related configuration information are stored on the "config server.

Mongod: database instance.

Ii. Actual operations

First, we prepare four apsaradb for mongodb instances.

1. Enable the config Server

Mongos should put the configuration information between mongod in config

configmongod --dbpath=F:\mongodb\bin --port 1111

2. Enable the mongos Server

Enable the mongos server and specify config. Here, we enable mongodb2 for my f drive and set the port to 2222.

mongosmongos --port 2222 --configdb=127.0.0.1:1111

3. Enable mongod

Corresponding to mongdb3 and mongodb4 of my f drive, ports are 3333 and 4444 respectively.

mongod --dbpath=F:\mongodb3\bin --port 3333mongod --dbpath=F:\mongodb4\bin --port 4444

3. Configure

1. According to the structure diagram, the customer directly deals with mongos. We connect directly to the mongos server and add the mongod server with ports 3333 and 4444 to mongos.

mongo 127.0.0.1:2222/admindb.runCommand({"addshard":"127.0.0.1:3333",allowlocal:true})db.runCommand({"addshard":"127.0.0.1:4444",allowlocal:true})
Enable the sharding function of the test Database
 mongos> use admin     switched to db admin    mongos> db.runCommand({"enablesharding":"test"})    { "ok" : 1 }
 mongos> db.runCommand({"shardcollection":"test.user","key":{"_id":1}})  { "collectionsharded" : "test.user", "ok" : 1 } 

①: Enable the database sharding function. The command is simple: enablesharding (). Here I will enable the test database.

②: Specify the part key in the set. Here I will specify it as the user. _ id field.

Iv. view results

Run db. printShardingStatus () to view the status.

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.