MongoDB Authoritative Guide Second Edition study note--mongodb Introduction

Source: Internet
Author: User

about MongoDB

MongoDB has a good balance between functionality and complexity, and greatly simplifies the previously complex task of supporting key features of today's mainstream Web applications: Indexing, replication, sharding, rich query syntax, and a particularly flexible data model. At the same time not sacrificing speed.

MongoDB is a powerful, flexible, and easy-to-scale universal database. Can extend a lot of functionality, such as two-level indexes, range queries, sorting, aggregations, and geospatial indexes.

Design features Easy to use

MongoDB is a document-oriented database that is more extensible than a relational database. Use a document instead of a row. Ability to use only one record to represent the hierarchical relationship of development.

The key and value of the document is no longer a fixed type and size.

easy to scale

MongoDB is designed with scale-out. The document-oriented data model makes it easy to split data between multiple servers.

MongoDB can automatically process data and load across the cluster, automatically reassign documents, and route user requests to the correct machine. If a cluster requires a large capacity, simply add a new server to the cluster andMongoDB will automatically transfer the existing data to the new server.

Rich features

MongoDB as a general-purpose database, in addition to additions and deletions, there are a series of unique features that are constantly expanding.

Index

MongoDB supports generic two-level indexes, allows for a variety of quick queries, and provides unique indexes, compliant indexes, geospatial indexes, and full-text indexes.

Aggregation

MongoDB supports "converged pipelines". Users can create complex aggregations through simple fragments and automatically optimize through the database.

Special Collection Types

MongoDB supports the existence of a limited set of time for data that will expire at some point, such as a session. Similarly,MongoDB also supports fixed-size collections for storing recent data, such as logs.

file Storage

MongoDB supports a very easy-to-use protocol for storing large files and file meta data.

MongoDB does not have connectivity and complex multi-line transactions Superior Performance

MongoDB can dynamically populate the document, and can pre-allocate data files to take advantage of the extra space in exchange for stable performance. MongoDB uses as much memory as the cache, trying to automatically select the correct index for each query.

MongoDB Basics

1. The document is The basic unit of data in MongoDB, very similar to the MySQL line, but more expressive.

2. A collection can be thought of as a table with a dynamic schema.

an instance of 3.MongoDB can have multiple separate databases, each with its own collection.

4. each document has a special key "_id"that is unique within the collection to which the document belongs.

The 5.MongoDB comes with a js Shellthat can be used to manage MongoDB instances or data operations.

documents (MySQL-like lines)

A document is an ordered set of key-value pairs. For example:{"Greeting": "Hello world!", "foo": 3}, the key of the document is a string. The key can be any utf-8 character. Except in a few cases:

    1. The key cannot contain A/ s (null character ). This character is used to denote the end of a key.
    2. . and the $ have a special meaning and can only be used in a specific environment.

MongoDB is not only distinguished by type, but also case-sensitive,{"foo":3}, {"foo": "3"}, {"foo":3} three documents are different.

MongoDB the document cannot have duplicate keys. {"foo": "3", "foo",3} document is illegal.

The key-value pairs in the document are ordered. {"x":1, "y":2} with {"Y":2, "x":1} is different.

collection (like a table in MySQL)

A collection is a set of documents.

Dynamic Mode

The collection is in dynamic mode. This means that the documents within a collection can be of various kinds. You can place any document, so why would you want to organize the relevant types of documents together, using multiple collections instead of putting them all together in a single collection? The reasons are as follows:

    1. Difficult to manage
    2. Speed is not cost-effective, it is much faster to query multiple collections separately.
    3. By placing documents of the same type in a collection, the data is more concentrated. Fewer disk seek operations.
    4. You can index a collection more efficiently by placing only one type of document in a collection.
naming

The collection is identified by name and can be any utf-8 string, except for the following special cases:

    1. cannot be an empty string (“”)
    2. cannot contain the \ s character ( null character ), which indicates the end of the collection name.
    3. Cannot use "system." Begins with a prefix reserved for the system collection. For example: System.users holds the user information of the database, System.namespaces holds all the database collection information.
    4. Cannot contain reserved characters ' $ '
Subset Collection

One convention for organizing collections is to use ". "separates subsets of different namespaces. To make the organizational structure clearer, such as (blog.posts and blog.authors), Although the subcollections do not have any special attributes, they are very useful. Using subcollections to organize your data is very efficient.

Database

multiple collections can form a database. A MongoDB instance can host multiple databases, each of which has 0 or more collections. Each database has independent permissions. Different databases are placed in different files.

naming

The database will eventually become a file in the file system, the database name is the corresponding file name, so there are many restrictions on naming. The database is identified by name. can be any utf-8 string, except for the following special cases:

  1. cannot be an empty string (“”)
  2. must not contain/,\,.,’’,*,<,>,:,|,?,$(a space),(NULL character). Basically, you can only useASCIIthe letters and numbers in the.
  3. Case-sensitive, should be all lowercase for simplicity.
  4. The database name is up to five bytes.
Keep database name

Some database names are reserved and can be accessed directly from these databases with special semantics.

Admin

from the authentication point of view, this is the "root" database. If a user is added to the admin Database, the permissions for all databases are automatically obtained. Furthermore, some specific server-side commands can only be run from the admin database, such as listing all databases or shutting down servers.

Local

This database can never be copied, and all local collections on a server can be stored in this database.

Config

when MongoDB is used for sharding settings, shard information is stored in the config database.

MongoDB Authoritative Guide Second Edition study note--mongodb Introduction

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.