MongoDB's understanding

Source: Internet
Author: User
Tags brew install mongodb install mongodb

First, what is MongoDB?

1, MongoDB is written by the C + + language, is a distributed file storage based open source database system. In the case of high load, adding more nodes can guarantee the performance of the server.

2. MongoDB is designed to provide scalable, high-performance data storage solutions for Web applications.

3,MongoDB store data as a document, data structure is composed of key value (key=>value) pairs. A MongoDB document is similar to a JSON object. Field values can contain other documents, arrays, and array of documents.

Second, history

1, Ten months, MongoDB by the 10gen team development. For the first 2 months of the year .

2.2012 May 23rd,MongoDB2.1 Development Branch was released ! This version features a new architecture that includes many enhancements.

3. On the day of the month, MongoDB 2.0.6 released, distributed document database.

4,2013 April 23rd,MongoDB 2.4.3 Released, this version includes some performance optimizations, enhancements, and bug fixes.

5, the year of the month , MongoDB 2.4.6 released, is currently the latest stable version.

Three, the main features

1, MongoDB provides a document-oriented storage, the basic idea is to replace the original "line " concept into a more flexible "document " model. A record can represent a very complex hierarchical relationship.

2. MONGO supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.

3, very easy to expand. In the face of rising data volume, there are usually two scenarios, one is to buy better hardware, not a decentralized data, distributed extension, the former has a very large disadvantage, because the hardware is usually a physical limit, when the limit is reached, processing power can no longer be extended. So the recommended approach is to use clusters for scaling. the document-oriented data model used by MongoDB enables it to automatically split data between multiple servers. It can also balance the data and load of the cluster, automatically rearrange the documents.

4, MongoDB supports a variety of programming languages: RUBY, PYTHON, JAVA, C + +, PHP, C # and other languages.

5, Rich function. Includes indexes, storage JavaScript, aggregations, fixed collections, file storage, and so on.

6, convenient management, in addition to starting the database server, almost no necessary management operations. To manage a cluster, you only need to know that there are newly added nodes, and the new nodes are automatically integrated and configured.

Four, installation

Brew Install MongoDB

V. Database

1, a MongoDB can build multiple databases.

2,a single instance of MongoDB can hold multiple independent databases, each has its own collection and permissions, different databases are placed in different files.

3, the database is also identified by the name. The database name can be any UTF-8 string that meets the following criteria .

1. Cannot be an empty string ("").

2. Must not contain ' (Space ),.,$,/,\ and/or (empty ).

3. Should be all lowercase.

4. Up to 64 bytes.

4, some database names are reserved, you can directly access these special functions of the database.

1.admin: from a permission point of view, this is the "root" database. If you add a user to this database, the user automatically inherits permissions from all databases. Some specific server-side commands can only be run from this database, such as listing all databases or shutting down the server.

2.local: This data is never copied and can be used to store any collection that is limited to a local single server .

3.config: When MONGO is used for sharding settings, theConfig database is used internally to hold information about the Shard.

Vi. Documentation

The document is the most central concept in MongoDB and is the core unit that we can use to analogy the document into each row of data in a relational database.

Multiple keys and their associated values are placed together in an orderly manner as documents. MongoDB uses the Bson structure to store data and network data exchange.

Bson data can be understood to add some data types that are not in JSON, based on JSON .

If we would have JSON, then we would have mastered half of the Bson, as I will introduce after the newly added data types.

Examples of documentation are as follows:

{name: " Zhang San", age:20,hobby:[" reading", " Travel", " singing"]}

It is important to note that:

1. The key /value pairs in the document are ordered.

2. The value in the document can be a string not only in double quotes, but also in several other data types (even the entire embedded document ).

3. MongoDB distinguishes between type and case.

4. MongoDB documents cannot have duplicate keys.

5. The key to the document is a string. In addition to a few exceptions, keys can use any UTF-8 character.

Document key naming specification:

The 1 key cannot contain a /s (null character ). This character is used to denote the end of a key.

2. and $ have special meaning and can only be used in certain circumstances.

3 The keys that begin with the underscore "_" are reserved (not strictly required ).

Seven, the collection

A collection is a combination of a set of documents. If a document is likened to a row in a database, then the collection can be likened to a database table.

The collection in MongoDB is modeless, meaning that the structure of the document stored in the collection can be different, such as the following two documents can be deposited into a collection at the same time:

{"Name": "Tangcaiye"}

{"Name": "Tangcaiye", "Sex": "Nan"}

Note: When the first document is inserted, the collection is created.

Valid set name

1. The collection name cannot be an empty string "".

2. The collection name cannot contain the \ s character (null character ), which represents the end of the collection name.

3. The collection name cannot be "system." Begins with a prefix reserved for the system collection.

4. User-created collection names cannot contain reserved characters. Some drivers do support inclusion in the collection name, because some system-generated collections contain that character. Never show $ in a name unless you want to access a collection created by this system .

MongoDB's understanding

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.