Why should I replace Mysql with Mongodb in the project?

Source: Internet
Author: User

At the early stage of the project design, I had the idea that, at the same time, I chose the final nosql solution to meet the following conditions:

1. Frequent demand changes: development must be more agile, development costs and maintenance costs should be lower, and rapid updates and evolution should be achieved. New functions should be launched in the shortest cycle.

2. Client/api support, because this directly affects development efficiency

3. easy deployment

4. Strong scalability

5. Saves system resources and consumes less cpu and other resources.

The nosql solution that meets these requirements leaves mongodb and redis. For redis, I am not saying that he is not good, but there is an important reason, the data processing format of our project is in JSON format, which plays a decisive role in the selection between the two.

Of course, Redis is very attractive for operations on a wide range of data types. It can easily solve some application scenarios, and its read/write performance is also quite high. The previous versions were linked by storage and memory hooks, in this way, if the storage of a large amount of data requires too much memory, of course, the current version has such a problem.

MongoDB is a document-oriented database, which is currently developed and maintained by 10gen. It has rich functions and is complete and can completely replace MySQL.

During the implementation of my project, I summarized some of the highlights of mongodb:

Why does MongoDB replace MySQL?

1. JSON-style syntax for easy understanding and understanding: MongoDB uses the JSON variant BSON as the internal storage format and syntax. All operations on MongoDB use JSON-style syntax, and the data submitted or received by the client is displayed in JSON format. Compared with SQL, it is more intuitive and easy to understand and master. This is also the reason why I chose mongodb based on my own project.

2. Schema-less: supports embedding sub-documents: MongoDB is a Schema-free document database. A database can have multiple collections, each of which is a Collection of Documents. The Table and Row of Collection and Document are not equal to those of traditional databases. Collection can be created at any time without prior definition. Collection can contain document records with different schemas. This means that the document in your previous record has three attributes, and the document in the next record can have 10 attributes, attribute types can be basic data types (such as numbers, strings, dates, etc.), arrays or hash, or even a sub-document (embed document ). In this way, you can implement the denormalizing data model to improve the query speed.

3. Easy-to-use query method: JSON is directly used, and range query and regular expression query are supported.

4. CRUD is simpler and supports in-place update: As long as an array is defined and the insert/update method passed to MongoDB can be automatically inserted or updated. For the update mode, mongoDB supports an upsert option, that is, "If a record exists, it will be updated; otherwise, it will be inserted ". MongoDB's update method also supports Modifier, which allows immediate updates on the server end, saving communication between the client and the server end. These modifer allows MongoDB to have a function similar to Redis, Memcached, and other KV features: Compared with MySQL, MonoDB is simpler and faster. Modifier is also a container that MongoDB can use to track user behavior. In practice, Modifier is used to quickly save user interaction behaviors to MongoDB for later statistical analysis and customization.

5. All attribute types support indexes and even Arrays: This makes some tasks very easy to implement. In MongoDB, the "_ id" attribute is the primary key. By default, MongoDB creates a unique index for _ id.

6. High Performance and speed: MongoDB uses c ++/boost to write data. In most cases, the query speed is much faster than that of MySQL, And the CPU usage is very small. Deployment is also very simple. For most systems, you only need to download the Binary Package and decompress it to run it directly, almost with zero configuration.

7. server scripts and Map/Reduce: MongoDB allows scripts to be executed on the server. You can use Javascript to write a function and run it directly on the server. You can also store the function definitions on the server, you can call it directly next time. MongoDB does not support transaction-level locking. You can use the Server side script to implement customized "Atomic" operations. At this time, the entire MongoDB instance is locked. Map/Reduce is also an attractive feature in MongoDB. Map/Reduce can perform statistics, classification, and merge on tables with large data volumes, and complete Aggregate functions such as the GroupBy of the original SQL statement. In addition, Mapper and Reducer use Javascript to define server scripts.

Related Article

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.