MongoDB beginners must read (both concepts and practices)

Source: Internet
Author: User
Tags mongodb interface mongodb server
MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. The supported data structure is very

MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. The supported data structure is very

I. Overview

MongoDB is an open source database project based on distributed file storage. Written in C ++. It is designed to provide a high-performance data storage solution that can be expanded for WEB applications.

MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. The supported data structure is very loose and is similar to the json bjson format. Therefore, it can store complicated data types. The biggest feature of Mongo is that it supports a very powerful query language. Its syntax is somewhat similar to an Object-Oriented Query Language. It can almost implement most of the functions similar to single-table queries in relational databases, it also supports data indexing.

Mongo mainly solves the access efficiency problem of massive data. According to official documents, when the data volume reaches 50 GB or more, Mongo's database access speed is more than 10 times that of MySQL. Mongo's concurrent read/write efficiency is not particularly good. According to official performance tests, it shows that it can process 5 thousand-1.5 read/write requests per second.

Because Mongo mainly supports massive data storage, Mongo also comes with an excellent Distributed File System, GridFS, which supports massive data storage, however, I have also seen some comments that GridFS has poor performance and needs to be verified.

Finally, Mongo is very popular because it supports complex data structures and has powerful data query functions, many projects consider using MongoDB instead of MySQL to implement non-complex Web applications. For example, why we migrated from MySQL to MongoDB is a real case of migrating data from MySQL to MongoDB, because the data volume is too large, the data query speed has been significantly improved when it is migrated to Mongo.

MongoDB also has a ruby project named MongoMapper, which imitates the MongoDB interface written by Merb's DataMapper. It is very simple to use and almost identical to DataMapper. It is very powerful and easy to use.

To sum up, monggDB features high performance, easy deployment, and ease of use, making it very convenient to store data. Features:

* It is designed for set storage and is easy to store object-type data.
* Free mode.
* Supports dynamic query.
* Full indexes are supported, including internal objects.
* Query is supported.
* Supports replication and fault recovery.
* Use efficient binary data storage, including large objects (such as videos ).
* Automatic fragment processing to support cloud computing-level scalability
* Supports RUBY, PYTHON, JAVA, C ++, PHP, and other languages.
* The file storage format is BSON (a json extension)
* Accessible through the network

The so-called "Collenction-Orented" means that data is stored in a data set by groups and is called a collection ). Each set has a unique identification name in the database and can contain an infinite number of documents. The concept of a set is similar to that of a table in a relational database service (RDBMS). The difference is that it does not need to define any schema ).
Schema-free means that we do not need to know any schema definitions for the files stored in the mongodb database. If necessary, you can store files of different structures in the same database.
The document stored in the set is saved as a key-value pair. The key uniquely identifies a document, which is a string type, and the value can be a complex file type. We call this storage form BSON (Binary Serialized dOcument Format ).

Recommended reading:

Install MongoDB2.4.3 in Ubuntu 13.04

How to create a new database and set in MongoDB

When using MongoDB, you must remember the following points: MongoDB is not very good at the following fields:

Ii. Installation

The MongoDB server can run on Linux, Windows, or OS X. It supports 32-bit and 64-bit applications. The default port is 27017. It is recommended to run on a 64-bit platform because MongoDB

The maximum file size supported when running in 32-Bit mode is 2 GB. MongoDB stores data in files (the default path is/data/db) and uses memory ing files for management to improve efficiency.

(1) Linux/OS X:
1. Create a data directory
Mkdir-p/data/db
2. Download the compressed package
Curl-O
3. decompress the file
Tar xzf mongodb-linux-i386-latest.tgz
4. Start the service
Bin/mongod run &
5. Use a client to connect
/Bin/mongo
6. Test
Db. foo. save ({a: 1 })
Db. foo. findOne ()

(2) In windows:

1. Create the data directory c: \ data \ db
2. Download the compressed package and decompress the file.
3. Start the service
Bin \ mongod.exe run
4. built-in clients
Bin \ mongon.exe

In LINUX and WINDOWS systems, the usage is similar. The difference is mainly the default data storage directory. LINUX systems are stored in/data/db, while WINDOWS

Stored in C: \ data \ db. You can use the -- dbpath parameter to specify the storage directory and start it at startup. For example: bin \ mongod.exe -- dbpath d: \ data \ mongo

Common Startup parameters:
Run is started directly. Example:./mongod run
-- Dbpath indicates that a specific storage directory is started. If the directory does not exist, it is created. Example:./mongod -- dbpath/var/data/mongo
-- Port specifies the port to start. Example:./mongod -- port 12345

Stop the MONGO service:
Method 1: Stop the server. You can use Ctrl + C
Method 2: Stop the client. You can connect to the client first.
./Mongo
And use the command
Db. shutdownerver ()
Then exit the client
Exit

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.