MONGO Learning and Finishing

Source: Internet
Author: User

As a member of the NoSQL family, MONGO is widely used and applied to production environments for its outstanding performance. The relational database (RDBMS ) remains an irreplaceable part of the Internet, and MONGO is based on NoSQL features that play an important role in applications where RDBMS is not applicable or performance is not high, inconvenient, and flawed.

The RDBMS is based on acid criteria design:

ACID, which is an abbreviation for the four basic elements that the database transaction performs correctly. Contains: atomicity (atomicity), consistency (consistency), isolation (isolation), persistence (durability). A support transaction (Transaction) database, must have these four characteristics, otherwise in the transaction process (Transaction processing) can not guarantee the correctness of the data, the transaction process is very likely not to reach the requirements of the counterparty.

NoSQL based on base idea cap theorem design:

(1) Basically Available: basic available;

(2) Soft-state: Soft state/flexible transaction, that is, the state can have a period of time of the different steps;

(3) Eventual consistency: final consistency;

The cap theorem refers to a distributed system in which consistency (consistency), availability (availability), Partition tolerance (partition fault tolerance) are not

MONGO does not support the operation of things, requires a program to simulate the situation or replace with RDBMS type database.

MONGO supports the atomicity of a single document basic operation. Bulk operations are non-atomic.

MONGO basic Operation Check Help.

Let's talk about MONGO's master-slave, cluster

MONGO has Master-slave mode replica-set mode share shard mode

The official website recommends replacing Master-slave mode with Replica-set mode;

1 MONGO master-slave mode

Master-Slave mode: A primary service, 1-n from the Service Master service has read and write permissions, from the service can be configured to do readable or only data redundancy. This mode does not have the function of fail-over, when the primary server fails, from the server does not have the function of writing, the service function part of the failure.

Primary server Configuration

1 fork=true2 logpath=/var/log/mongodb.log3 logappend=true 4 port=100005 journal=true6 dbpath=/data/mongo/master7 Master=true

From server configuration

1 fork=true2 logpath=/var/log/mongodb.log3 logappend=true 4 port=100015 journal=true6 dbpath=/data/mongo/slave7 Slave=true8 source=127.0.0.1:10000

Start the server in turn to achieve master-slave configuration. If you are not readable from the server, you can execute Db.setslaveok () from the server

2 replica-set (Replica set) mode: This mode consists of two or more server +arbiter. In this mode, 1 are selected from N normal services as the main service, the other is the secondary server, and the Arbiter quorum assists in selecting a new primary server for failover when the primary server fails.

Server configuration:

# 0Fork=Truelogpath=/var/log/mongodb.loglogappend=Trueport=10010Journal=Truedbpath=/data/mongo/replica/arbiter#1Replset=rs0fork=Truelogpath=/var/log/mongodb.loglogappend=Trueport=10011Journal=Truedbpath=/data/mongo/replica/1Replset=rs0#2Fork=Truelogpath=/var/log/mongodb.loglogappend=Trueport=10012Journal=Truedbpath=/data/mongo/replica/2Replset=rs0

Three servers are configured to start sequentially

var replicasetconfig = {     "Rs0", Members     : [        0,           host: ' localhost:10012 ',          },        1,           host: ' localhost:10011'        },         2,            Host: ' localhost:10010 ',           arbiteronly:true        }    ]  }

Rs.initiate (replicasetconfig) configures the replica set.

3 Shard Mode

In fact, shards are built on other patterns.

# Configfork=truelogpath=/var/log/mongodb. loglogappend=trueport=3000Journal=truedbpath=/data/mongo/config# share route Fork=Truelogpath=/var/log/mongodb. loglogappend=trueport=3001configdb=localhost:3000

Mongos-f share routing. conf

Go to MONGOs configuration shard

Sh.addshard (" rs1/mongodb0.example.net:27017 ")
Sh.addshard ("mongodb0.example.net:27017")
sh.enablesharding (dbname)
Sh.shardcollection ("Records.people", {"ZipCode": 1, "name": 1})
sh.shardcollection (" People.addresses ", {" state ": 1," _id ": 1})
sh.shardcollection (" Assets.chairs ", {" type ": 1," _id ": 1})
sh.shardcollection ("Events.alerts", {"_id": "Hashed"})

< Span class= "Mi" > < Span class= "p" > < Span class= "p" >  
/span>
< Span class= "Mi" > < Span class= "p" > < Span class= "p" > good mess!

MONGO Learning and Finishing

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.