At the beginning of the project design, I had this idea, but also in the following conditions to meet the situation to choose the final NoSQL program:
1, the demand changes frequently: develops to be more agile, the development cost and the maintenance cost is lower, must be able to update the evolution quickly, the new function should be in the shortest cycle time on-line.
2, the client/API support, because this directly affects the development efficiency
3. Simple Deployment
4. Strong expansion Ability
5, save the system resources, CPU and other resources to spend less
To meet these requirements of the NoSQL solution, there are MongoDB and Redis, for Redis, I am not saying that he is not good, but there is an important reason, our project data processing format are in the form of JSON to deal with, this is the choice between the two later, Play a decisive role.
Of course, Redis is attractive to rich data types, you can easily solve some of the application scenarios, its read and write performance is also very high, the previous version is the storage and memory hooks are linked, so if the storage of large amounts of data requires too much memory, of course, the current version has no such problem.
MongoDB is a document-oriented database, currently developed and maintained by 10gen, it features rich, complete, can replace MySQL completely.
In the course of my project implementation, I summed up some of the MongoDB's good highlights:
Why MongoDB can replace MySQL?
1, use JSON style syntax, easy to grasp and understand: MongoDB use JSON variant Bson as internal storage format and syntax. For MONGODB operations, the JSON-style syntax is used, and data submitted or received by the client is presented in JSON format. More intuitive, easier to understand and master than SQL. This is also according to my own project situation, finally chose the MongoDB one of the reasons.
2, schema-less, support embedded subdocuments: MongoDB is a schema-free document database. A database can have multiple collection, and each collection is a collection of documents. Collection and document and the traditional database table and row are not equal. You do not need to define collection beforehand, you can create it at any time. Collection can contain document records with different schemas. This means that the document in your previous record has 3 attributes, the document for the next record can have 10 properties, and the type of the property can be either a basic data type (such as a number, a string, a date, and so on), an array or hash, or even a subdocument (embed document). In this way, the inverse normalization (denormalizing) data model can be implemented to improve the speed of the query.
3, Easy-to-use Query method: Direct use of JSON, support range query, regular expression query.
4, crud simpler, support in-place update: As long as the definition of an array, and then passed to MongoDB Insert/update method can be automatically inserted or updated, for update mode, MONGODB support a upsert option, namely: " If the record exists then the update is inserted. The MongoDB Update method also supports modifier, which enables immediate updates at the server end, eliminating client and server communication. These modifer allow MongoDB to have similar functions as KV Redis and memcached: simpler and faster than MYSQL,MONODB. Modifier is also a container that MongoDB can be tracked for user behavior. In practice, modifier is used to quickly save user interaction behavior to MongoDB for later statistical analysis and personalized customization.
5. All attribute types support indexes, even arrays: this can make certain tasks very easy to implement. In MongoDB, the _id property is the primary key, and the default MongoDB creates a unique index for _id.
6, High-performance, fast: MongoDB use c++/boost writing, in most cases, its query speed compared to MySQL faster, for CPU occupied very small. Deployment is also very simple, for most systems, simply download the binary package after decompression can be directly run, almost 0 configuration.
7, server-side scripts and Map/reduce:mongodb allow scripts to be executed on the server side, you can write a function in JavaScript, execute directly on the server, or store the definition of the function on the server, and then call it next time. MongoDB does not support transaction-level locking and can be implemented using the server side script for certain "atomicity" operations that require customization, at which point the entire mongodb is locked. Map/reduce is also an attractive feature in MongoDB. Map/reduce can count, classify and merge the large data table, complete the functions of the original SQL GroupBy and other aggregate functions. And the definition of mapper and reducer is to use JavaScript to define server-side scripts.