Introduction to MongoDB

Source: Internet
Author: User

Address: http://www.mongodb.org/display/DOCS/Introduction

 

MongoDB is not designed in the lab. It comes from our experience in building large-scale, highly practical, and robust systems. We are not starting from scratch. We want to point out the problem and reverse the situation. So the method I want to consider for MongoDB is that if you use MySQL and want to switch from a relational database to a document-based database (MongoDB is a document-based database.), You get a lot of excellent features: binding documents improves the speed, ease of management, and agile development through the schema-free database, it is easier to horizontally expand (because the connection is no longer important ). Relational databases have many important things: Index, dynamic query, and update. But we do not need to change much. For example, the design of indexes in MongoDB should be exactly the same as that in MySQL and Oracle. You have the right to decide whether to index the bound fields.

-Eliot Horowitz: 10 CTO and co-founder

Why MongoDB?

Document-oriented

The documentation (object) can map programming language data types well.

Binding documents and arrays reduces connection requirements

Dynamic type (NO mode) facilitates mode Evolution

No connections and no multi-document transactions improve performance and scalability

High Performance

No connection and binding makes reading and writing faster

The index includes the index of keys bound to documents and arrays.

Optional stream writing (no confirmation required)

High Availability

The backup server can automatically recover from faults.

Scalability

Automatic partitioning (automatically partitioning data through the server)

Read/write allocation across slices

Connectionless and multi-document transactions make distributed queries more convenient and convenient

Eventually consistent read can be allocated through the backup server

Rich Query Language

Large-scale deployment

1. One or more shards, each of which carries one partition of all data (automatically managed ). The read and write operations are automatically sent to appropriate shards. Each Shard is supported by a backup set (the backup set only carries the data of the shard ).

A backup set is one or more servers, each carrying copies of the same data. At any time, one of them is the primary set and the other is the secondary set. If the primary set fails, one of the secondary sets automatically becomes the primary set. All write and consistent reads are in the primary set, and all final consistent reads are distributed in the secondary set.

2. Multiple configuration servers each carry a copy of metadata to indicate which data is on which part.

3. One or more routers each act as one server for one or more clients. The client sends a query update request to the vro. After querying the configuration server, the vro routes the request to the appropriate shard.

4. One or more clients, each of which is a part of a user application, send commands to the router in their own language through the Mongo client library (driver.

In the figure, mongod is a server program (data or configuration ). Mongos is a router program.

Small-scale deployment

1. One backup set (automatic fault recovery), or one server with 0 or multiple slave machines (automatic fault recovery is not supported)

2. One or more clients send commands to backup sets as a whole or a single manager.

L Data Model

<! -- [If! Supportlists] --> · A Mongo System (refer to the above deployment) carries multiple databases)

<! -- [If! Supportlists] --> · A database carries multiple collections)

<! -- [If! Supportlists] --> · A collection carries multiple document

<! -- [If! Supportlists] --> · A document contains multiple fields.

<! -- [If! Supportlists] --> · A field is a key-Value Pair

<! -- [If! Supportlists] --> · A key is a string name.

<! -- [If! Supportlists] --> · A value is

<! -- [If! Supportlists] --> · basic data types (string, integer, float, timestamp, binary, etc)

<! -- [If! Supportlists] --> · Documentation

<! -- [If! Supportlists] --> · array of Values

Mongo Query Language

To retrieve some data from the database collection, you must provide a document to query and match the fields you want.

For example, {Name: {First: 'john', last: 'doe '} matches all documents whose names are John Doe in the set.

Similarly, {name. Last: 'doe '} will match all documents whose names are doe.

In addition, {name. Last:/^ d/} will match the document whose last name starts with D (Regular Expression matching ).

The query will also match the internally bound array. For example, {keywords: 'store'} matches documents with storage in the keyword array.

Similarly, {keywords: {$ in: ['store', 'dbms ']} matches documents with storage or DBMS in the keyword array.

If your collection contains a large number of documents and you want to perform a quick query, you can create an index for the query.

For example, ensureindex ({name. Last: 1}) or ensureindex ({keywords: 1 }).

Note that indexes occupy space and reduce the update efficiency, so you can only use them when they are worth a compromise.

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.