[Mongodb] Talking about the characteristics of MongoDB and the difference with MySQL (with MangoDB installation tutorial)

1. What is MongoDB

        MongoDB is a document-based NoSQL database . Data is stored in MongoDB in the form of documents (corresponding to records in relational databases). Documents are actually JSON strings. The advantage of using JSON is that it is very intuitive. Through a series of Key- Value key-value pairs to represent data, in line with our reading habits. Both Java and Python have good support for JSON. After the data is read from MongoDB, it can be used directly without conversion; it supports rich data structures, and Value can be ordinary integers, strings, arrays, nested The advantage of using nesting is that you can get the data you need with only one simple query in MongoDB.

2. Application scenarios of MongoDB

1. MongoDB transaction

MongoDB currently only supports single-document transactions, and MongoDB is temporarily not suitable for scenarios that require complex transactions. The flexible document model stored in JSON format is closest to the real object model, which is friendly to developers and facilitates rapid development iterations. Available replica sets meet the requirements of high reliability and high availability of data. The operation and maintenance are relatively simple, and automatic fault switching can expand the mass of fragmented clusters. data storage.

2. Multiple engines support various powerful indexing requirements

  • Support geolocation index
  • Can be used to build various O2O applications
  • Text indexing solves search needs
  • TTL index solves the demand for historical data expiration
  • Gridfs solves the needs of file storage
  • Aggregation & mapreduce solves the needs of data analysis scenarios. You can write query statements or scripts yourself, and distribute the requests to MongoDB for completion.

3. Specific application scenarios

Traditional relational databases are unable to solve the three high problems. What are the three highs?

  • High performance - The requirement for high concurrent read and write of the database.
  • Huge Storage - The need for efficient storage and access to massive amounts of data.
  • High Scalability && High Availability - The need for high scalability and high availability of the database. MongoDB can perfectly solve the three high problems.

4. The following are several practical application cases:

(1) Game scene Use MongoDB to store game user information, equipment, points, etc., and store them directly in the form of embedded documents, which is convenient for query and update.

(2) The logistics scenario uses MongoDB to store order information, order status, and logistics information. The order status is iterated rapidly during the delivery process and stored in the form of an embedded array in MongoDB. One query can find out all the changes of the order. Awesome plus. (3) Social scene Use MongoDB to store user information and circle of friends information, and realize nearby people and positioning functions through geographic location index.

(4) IoT scenarios Use MongoDB to store device information, log information reported by devices, and perform multi-dimensional analysis on these information.

(5) Live video use MongoDB to store user information and like interactive information.

5. Summary of scenarios for choosing MongoDB:

  • Big amount of data
  • Frequent read and write operations
  • The value of data is low and the requirements for transactions are not high

3. MongoDB vs. MySQL

keyword comparison

4. Data Model

The smallest storage unit of MongoDB is a document object, which is equivalent to a row in MySQL, and data is stored on disk in the form of BSON documents. BSON is a binary storage format, referred to as Binary JSON. Like JSON, BSON supports embedded document objects and array objects, but BSON has some data types that JSON does not, such as Date and BinData types. BSON adopts a name similar to the C language structure, supports embedded document objects and array objects, and has three characteristics: lightweight, traversable, and efficient. It can effectively describe unstructured data and structured data, and is flexible. The performance is high, but the space utilization rate is not very ideal. In addition to the basic String, integer, boolean, double, null, array, and object in BSON, MongoDB also supports some special data types, such as date, object id, binary data, regular expression, and code.

Five, the characteristics of MongoDB

1. High performance

MongoDB provides high performance data persistence. Support for embedded data models reduces IO activity on database systems. Indexes enable faster queries and contain keys for embedded documents and arrays.

  • Text indexing solves search needs;
  • TTL index solves the need for automatic expiration of historical data;
  • Geographical location index can be used to build various O2O applications;

2. High availability

MongoDB's replication tool is called a replica set (reolica set), which includes automatic failover and data redundancy.

3. High availability

MongoDB provides horizontal scalability as part of its core functionality. Sharding distributes data across a cluster of machines. (Massive data storage, horizontal expansion of service capabilities) Starting from 3.4, MongoDB supports the creation of data regions based on shard keys. In a balanced cluster, MongoDB directs the reads and writes covered by a region only to those shards in the region.

4. Rich query support

MongoDB supports a rich query language, supports read and write (CRUD) operations, such as data aggregation, text search, geospatial query, etc.

5. Other features

Such as dynamic mode, flexible document model.

6. Download and install MongoDB

1. MongoDB official website download address

https://www.mongodb.com/try#community

2、Products – servers

3、MongoDB Community Server

4. Select the release version

5. Download the zip file and unzip it

6. Create the data/db directory and start the program from the command line

mongod --dbpath=..\data\db

7. Since vcruntime140_1.dll cannot be found, the code cannot continue to be executed

7. The code cannot continue to be executed because vcruntime140_1.dll cannot be found

1. Download the vcruntime140_1.dll file

2. Copy the vcruntime140_1.dll file to C:\Windows\System32

3. Start the program again from the command line

mongod --dbpath=..\data\db

4. The default port number of MongoDB is 27017

If you want to modify the port number, you can specify the port number through –port.

Eight, install the compass graphical management tool

1. Download address

https://docs.mongodb.com/compass/master/install/

2. Compass is successfully installed and started

点击MongoDBCompass.exe

3. Compass connects to MongoDB

mongodb://127.0.0.1:27017

Guess you like

Origin blog.csdn.net/gongzi_9/article/details/125917922