-
What is the mongo
-
How do I know I need to learn MongoDB
-
What developers should know about MongoDB
-
Learning choices and dilemmas
Let’s take a look at what MongoDB is.
NoSQL refers to a non-relational database. It is a relative term for a relational database. MongoDB is one of the more well-known types of non-relational databases (NoSQL).
It has many excellent features, such as high performance, high availability, support for rich query statements, no pre-defined data model and horizontal scalability, suitable for storing structured, semi-structured documents and documents in specific formats, which make it popular with many developers.
Let’s look at a few examples to see how MySQL differs from MongoDB.
Unlike MySQL databases, MongoDB does not require predefined tables and fields, which is a sign of its flexibility. MongoDB can have multiple databases, each database can have multiple collections, each collection can store multiple documents, this relationship is similar to the “database, table, data” in SQL database. The following diagram illustrates the relationship between databases, collections, and documents in MongoDB:
The database FOtoo has two collections, player and books. Each collection contains many documents, such as the documents about the book dream of Red Mansions in the collection Books and the documents about the player James in the collection Player.
In terms of queries, a simple MySQL query is SELECT * FROM tablename and the corresponding MongoDB query is db.tablename.find(). MongoDB works better when faced with multi-step query conditions. Such as:
“Count the number of documents in the arTIC database with a score greater than 70 and less than 90”
Such requirements can be easily accomplished with MongoDB’s aggregation operations, as shown in the following example:
> db.artic.aggregate([
... {$match: {score: {$gt: 70, $lt: 90}}},... {$group: {_id: null, number: {$sum: 1}}}
... ])
Copy the code
This example might be a little bit simpler, and in MySQL we can do it with count and WHERE, but what if it’s four or five levels more complicated? For example, on this basis, the operation, replacement, sorting, grouping counting, adding and deleting fields of a certain field will be very troublesome to achieve with MySQL, while the aggregation of MongoDB can make us easily complete this kind of complex requirements.
How do I know I need to learn MongoDB
MongoDB is a member of the first tier of dozens of NoSQL that have emerged in recent years, the other being Redis.
You might have “How do I know I need to learn MongoDB? “Such a question, in the face of this problem, we can start with the characteristics and application scenarios of MongoDB:
-
MongoDB is suitable for storing documents that are structurally determined or uncertain. For example, the information crawled by crawler often has missing fields or uneven fields.
-
High database availability requirements. MySQL and other databases need to use external tools to achieve load balancing, automatic disaster recovery and data synchronization, while MongoDB’s replication set allows us to easily complete this series of work. Replication sets are more stable than third-party tools.
-
Database partition table is a common database optimization method used in WEB development. MySQL database partition table has many problems to consider, such as field redundancy, cross-node paging of data assembly, sorting and data migration, etc., while MongoDB sharding allows us to easily complete the work of “database partition table”. MongoDB sharding allows us to focus on specific requirements rather than on the problems caused by “repository and table”.
-
Similarly, MySQL’s permission control, data model definition, database backup and restore functions are also available on MongoDB.
-
MongoDB supports location storage and query, which means MongoDB can be used for bike-sharing, umbrella sharing, car locating and other services.
Our commonly used relational database can not meet the needs of the WEB2.0 era, exposing a lot of problems that are difficult to overcome in practical application. NoSQL was created to address challenges such as massive data storage, elastic scalability, and flexibility, so as a qualified developer, you should take the time to learn about databases other than SQL.
What developers should know about MongoDB
Before learning, we need to understand our position as a professional DBA or daily development user.
MongoDB has a complete system and corresponding certification exams. For those who want to become a professional DBA, I suggest visiting the official website of MongoDB.
For those of you who just need to meet your daily development needs, I recommend the following:
-
How to install MongoDB on each platform
-
Basic operations of MongoDB databases and collections
-
MongoDB document CRUD operations, including projections and modifiers that enrich CRUD
-
MongoDB streams aggregation operations, which make it easy to process complex data at the database level rather than in a programming language
-
MongoDB’s data model. Although MongoDB can store irregular documents, there are cases where defining a data model can improve query efficiency
The following diagram depicts the complete process of an aggregation operation:
Of course, in addition to these basic operations, we can also learn more knowledge to improve personal competitiveness, such knowledge is:
-
MongoDB executes plan and index. Execution plan allows us to clearly understand the efficiency of query statements, while index is a common means to optimize query efficiency
-
MongoDB replication set, which is the best way to improve MongoDB availability and ensure that data services do not stop
-
MongoDB sharding, sharding can ensure efficiency after the amount of data becomes large
-
MongoDB things, if you’re using MongoDB for WEB sites, things are something you have to learn
-
MongoDB database backup and restore. With replica sets, backups become less important, but not without the need. And MongoDB backups can be down to documentation, which makes a lot of sense.
Learning choices and dilemmas
Developers with some work experience will, in most cases, teach themselves. Some searched the web for corresponding articles, others simply thumbed through official documents.
I recommend scrolling through official documents and using search engines to find articles shared by people when they encounter a difficult point of view.
The advantages of self-study are many and the disadvantages are also obvious. Such as:
-
Intermittent learning, difficult to maintain focus, resulting in poor knowledge absorption
-
It takes a lot of time. You know what you need to learn, but the documents aren’t laid out the way you want them to be, so it takes a lot of effort to go through them
-
Knowledge is not systematic, look east and west, no induction is easy to forget
-
To study, you need to take notes, which is another time-consuming thing
-
Some of the points in official documents are hard to understand, and getting stuck halfway is uncomfortable
-
I learned one or two months sporadically, and I’m not sure whether I learned it or not
If you don’t study by yourself, you’ll have to find some structured tutorials to help you progress quickly and avoid detdetments. In the era of knowledge payment, it is also a good choice to invest appropriately when conditions permit.
But in the face of hundreds of fees, many developers still feel a little pressure, after all, we move brick economic pressure is also very big. With these issues in mind, here’s Wei Shidong’s highly cost-effective MongoDB Zero-Based Quick Start Tutorial, which costs less than 10 RMB.
Article author Wei Shidong is: Turing signed author, signed author of Publishing House of Electronics Industry, Huawei cloud certification cloud enjoy expert, gold digging community outstanding author, open source project AIOWebSocket author. So in the quality of the article, we can rest assured.
This article covers almost all of the topics we mentioned above. After reading this article in just 50,000 words, you will learn:
-
CRUD operations and Cursor objects for the document
-
Master streaming aggregation operations, easily facing any data processing requirements
-
Understand MongoDB query efficiency and optimization
-
How can MongoDB be made more usable
-
How to deal with data service failures
-
Understand access control for MongoDB
-
Learn to use data models to reduce data redundancy and improve efficiency
-
Master mongodump data backup and restoration methods
In this way, you can be competent for the daily development of the database operation ability requirements. This article is suitable for zero-based developers who are interested in MongoDB or who have some foundation and want to continue to consolidate and deepen their learning.
The article is long in length and detailed in content, and there is no lack of high-quality illustrations, such as the diagram describing the node relationship of replication set:
A graph describing a node where a primary point is dropped and a primary node is re-elected
If you feel the need to learn about MongoDB and this article is what you want, go subscribe!