MongoDB Study Notes-Charm

Source: Internet
Author: User
Tags mysql functions

MongoDB is one of the most popular NoSQL databases today. During the summer vacation, I finally had time to read some articles about it from the MongoDB authoritative guide and NoSQL Fan, below I will briefly summarize some interesting things of MongoDB. For the basic operations, O & M, and usage of MongoDB, you can read books or learn materials by yourself.

1. Compared with other NoSQL

The book MongoDB: The Definition Guide says, "If you cannot use it, The technology that you use is nothing more. MongoDB is dedicated to being easy to use and easy to use ". Some time ago, Chun Hui, a brother of Alibaba who was engaged in HBase, spent more than two hours explaining some of HBase's things in depth. Compared with the implementation of Big Data based on HDFS such as HBase, its architecture and layers are more complex. Cassandra, which Facebook is proud of and no longer maintains, will inevitably make people feel less promising.

The MongoDB community is still quite active. MongoDB is a document-oriented database. It is currently developed and maintained by 10gen and has rich functions and is complete.

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.

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.

CRUD is simpler and supports in-place update: you only need to define an array and then pass the insert/update method to MongoDB to automatically insert or update it. 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.

High performance and high speed: MongoDB uses c ++/boost for writing. 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.

2. Supports multiple replication Modes

MongoDB supports replication between different servers, including fault tolerance solutions for dual-host mutual backup. Master-Slave is the most common. You can use Master-Slave to back up data. In our practice, we use the Master-Slave mode. Slave is only used for backup, and the actual read/write operations are performed from the Master node. Replica Pairs/Replica Sets allow two MongoDB instances to listen to each other, enabling fault tolerance for dual-host mutual backup.

3. MongoDB Integration

MongoDB's shell commands fully support js, and are more diverse than js, and can store js functions and variables. MongoDB comes with the Mapreduce function, but this MapReduce function only supports js syntax (Function map and reduce are written in js ), the implementation of the js engine allows an instance to run only one map/reduce thread. MongoDB allows you to execute scripts on the server. You can use Javascript to write a function and directly execute the function on the server. You can also store the function definition on the server. You can call the function directly next time. MongoDB does not support transaction-level locking. For some "Atomic" operations that need to be customized, you can use the Server side script to implement the operation. At this time, the entire MongoDB is locked. Map/Reduce is also an attractive feature in MongoDB. Map/Reduce allows you to compute, classify, and merge tables with large data volumes, and implement Aggregate functions such as GroupBy in the original SQL statement. In addition, Mapper and Reducer use Javascript to define service-side scripts. In addition, the regular expressions supported by MongoDB shell are Perl-compatible PCRE. MongoDB supports java drivers and can be used in combination with script languages such as Python, PHP, and Ruby, such as PyMongo.

4. GridFS

GridFS is used to store sophomore files in MongoDB. The basic idea is to make the files into multiple blocks and store each block as a separate document. If you use./configure file put filename, the file will be stored in GridFS. After md5 processing, it will be stored in the fs. files database of MongoDB. GridFS can be used to store videos and images, while MongoDB supports Sharding and Replica Set. It also solves the distributed storage problem, so it is tempting. Attached an example: Image Storage Based on MongoDB GridFS

5. Product substitution and Evolution

LAMP (linux + apache + mysql + php) is a beacon in web development. With the expansion of web applications, more and more Nginx began to replace apache, And the cache layer gradually weakened mysql functions, more and more NoSQL products are challenging MySQL with its simplicity, flexibility, and high performance. A new combination: Unix systems and node. js, coupled with MongoDB to form a new web development framework.

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.