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
Advantages of MongoDB
- High Performance and fast speed (if your memory is sufficient)
- There is no fixed table structure and data migration is not required to modify the table structure
- Easy to use
- Horizontal scaling using Sharding
- Easy deployment
When using MongoDB, remember the following points:
- MongoDB suppose you have a large disk space.
- MongoDB assumes that your memory is larger than enough to put down your hot data.
- Assume that you deploy MongoDB on a 64-bit System (32-bit has 2 GB limit, and you can try it again)
- MongoDB assumes that your system is little-endian
- MongoDB assumes that you have multiple machines (not dedicated to standalone reliability)
- MongoDB assumes that you want to change security to performance while allowing you to change performance to security.
MongoDB is not very good at the following fields
- Not very stable, especially auto-sharding still has many problems
- SQL is not supported, which means that many of your tools that use SQL interfaces are no longer applicable.
- Persistence: MongoDB has low reliability and may lose data for a period of time.
- There are few related documents, and the new functions all have this problem.
- Related talents are hard to find, which is also one of the new features.
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 http://downloads.mongodb.org/linux/mongodb-linux-i686-latest.tgz
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