“This is the third day of my participation in the First Challenge 2022, for more details: First Challenge 2022”.

What is MongoDB

1. Wikipedia

MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications. MongoDB is a product between relational database and non-relational database. Among non-relational databases, it has the most rich functions and is the most like relational database. It supports a very loose data structure in the JSON-like Bson format, so it can store complex data types. The biggest feature of Mongo is that it supports a very powerful query language, its syntax is somewhat similar to object-oriented query language, almost can achieve the majority of functions similar to relational database single table query, but also supports the establishment of indexes to data.

2. In a nutshell

MongoDB is a document-type NoSQL database, data is stored in MongoDB in the form of documents (records corresponding to relational databases), documents are actually JSON strings, the benefits of USING JSON is very intuitive, through a series of key-value pairs to represent data, It fits our reading habits. JSON has good support in Java and Python. After data is read from MongoDB, it can be used directly without conversion. Support rich data structure, Value can be common integer type, string, array, nested subdocument, the advantage of using nesting is in MongoDB only a simple query can obtain the data you need.

2. Application scenarios of MongoDB

1. MongoDB transactions

Currently, MongoDB only supports single document transactions. MongoDB is not suitable for scenarios requiring complex transactions. Flexible DOCUMENT model JSON format storage is closest to the real object model, friendly to developers and convenient for rapid development and iteration. Replication set can meet the requirements of high reliability and high availability of data, simple operation and maintenance, automatic failover of faults, scalable fragmented cluster mass data storage.

2. Multiple engines support a variety of powerful indexing requirements

  • Geolocation index is supported
  • It can be used to build various O2O applications
  • Text indexing addresses the need for search
  • The TTL index addresses the need for historical data expiration
  • Gridfs addresses file storage needs
  • Aggregation and MapReduce solve data analysis scenarios. You can write your own query statements or scripts and send requests to MongoDB.

3. Specific application scenarios

The traditional relational database is unable to solve the three high problems. What are three heights?

  • High performance – High concurrent read and write requirements for the database.
  • Huge Storage – The need for efficient Storage and access to massive amounts of data.
  • High Scalability && High Availability- The Scalability and Availability of the database.

MongoDB can solve the three-high problem perfectly.

4. Here are some practical application cases:

(1) Game scenes use MongoDB to store game user information, equipment, points, etc., which can be directly stored in the form of embedded documents for easy query and update. (2) In the logistics scenario, MongoDB is used to store order information, order status and logistics information. The order status is rapidly iterated in the delivery process and stored in the form of MongoDB embedded array. All changes of the order can be found out in a single query, which is awesome plus. (3) In social networking scenarios, MongoDB is used to store user information and friend circle information, and the nearby people and location functions are realized through geographical location index. (4) iN the Internet of Things scenario, MongoDB is used to store device information and log information reported by devices, and carry out multidimensional analysis on these information. (5) MongoDB is used to store user information and interactive information of liking for live video.

5. Summary of scenarios for selecting MongoDB:

  • Large amount of data
  • Frequent read and write operations
  • Data value is low and transaction requirements are not high

Third, MongoDB compared with MySQL

Keyword comparison

4. Data model

The minimum storage unit of MongoDB is a document object, which is equivalent to a row in MySQL. The data is stored on disk in the form of a BSON document. BSON is a storage format in Binary form, Binary JSON for short. 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. BSON uses a name similar to C language structure and supports embedded document objects and array objects. It is lightweight, traversable and efficient. It can effectively describe unstructured data and structured data with high flexibility, but the space utilization rate is not very ideal. In addition to basic String, INTEGER, Boolean, double, NULL, array, and Object, MongoDB supports some special data types. Date, Object ID, Binary Data, Regular expression, and code.

5. Characteristics of MongoDB

1. High performance

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

  • Text index solves the need of search;
  • TTL index solves the requirement of automatic expiration of historical data.
  • Location index can be used to build various O2O applications;

2. High availability

MongoDB’s replication tool, called a Reolica set, 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 and horizontal expansion of service capabilities) Starting from 3.4, MongoDB supports the creation of data regions based on slice keys. In a balanced cluster, MongoDB directs reads and writes covered by a region to only those slices in the region.

4, rich query support

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

5. Other features

Dynamic patterns, flexible document models.

Download and install MongoDB

1. Download the MongoDB official website

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

2, Products — servers

3. MongoDB Community Server

4. Select Release

5. Download the ZIP file and decompress it

6, create data/db directory, command line start program

mongod --dbpath=.. \data\db

Unable to continue executing code because vcrUntime140_1.dll cannot be found

Unable to continue executing code 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

mongod --dbpath=.. \data\db

4. The default MongoDB port is 27017

To change the port number, run the -port command.

Install compass graphical management tool

1. Download address

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

Compass is successfully installed and started

Click MongoDBCompass. Exe

Compass Connect to MongoDB

Mongo: / / 127.0.0.1:27017