Original The use of MongoDB in the system

Source: Internet
Author: User
Tags findone processing text

order) NoSQL is not about replacing the original data product, but rather providing more choices for different scenarios.

a) structure type

  The domain of traditional databases lies in structured documents, which can be processed for unstructured documents and semi-structured documents, but with a certain flaw, and what are structured documents, summarized as follows:

  Structured Information -This information can be found in a relational database that has dominated it applications for years. This is the information that the mission-critical OLTP system relies on, and in addition, it can sort and query the structure database information;

  Semi-structured information -This is the second wave of it, including e-mail, word-processing files, and large amounts of information stored and posted on the web. Semi-structured information is based on content, can be used for search, which is the reason for the existence of Google;

  unstructured Information --This information can be considered primarily as bit mapping data in its essential form. The data must be in a perceptible form (such as being heard or viewed in audio, video, and multimedia files). Many big data are unstructured, and their sheer scale and complexity require advanced analytic tools to create or exploit a structure that is easier for people to perceive and interact with.

II) differences between MongoDB and line-directed databases

  To be honest, I think that the NoSQL field is more wonderful things are hive, but this does not introduce it, for the project to use to MongoDB, there is a certain reason, I always thought that nosql this thing and row-oriented database does not conflict, it is only a complement of row-oriented data, For MongoDB, it and we use the mysql,oracle and so on what difference, once I also looked for some things, found on-line a lot of related articles are the same, almost exactly the same, no value, and then fathom their own summary.

Give me a chestnut:

Uid Name Age
1 Tom 18

  In the table above, very straightforward, the data is very intuitive, but if we need to store another thing: avatar, the average person will do this:

Uid Name Age Photo
1 Tom 18 ./upload/1.png

  Although different databases provide direct storage of binary database fields, but I will choose the above storage, I believe there are many people will do so, there is nothing wrong with this, but if our files are large, a few GB, then whether read or write will be time-consuming, become the bottleneck of the system, Based on this situation, cloud computing and NoSQL are born, which means that the reason for the birth of Hadoop,hbase is:

  With the rapid increase of disk storage capacity over the years, access speed-disk data read speed has not kept pace with the times, the increase in addressing time is much slower than the increase in transmission rate, addressing is to move the disk to a specific disk location for read and write operations, which is the main cause of disk operation delay, and the transfer rate depends on the disk bandwidth.

So people came up with a way: since it takes 100 hours to read a file in a server, then put the file on 100 servers, each server put 1% of the data, then 1 hours will be done , this is the core idea of Hadoop, MongoDB database inherits this idea, its chunk Division, and node division, all continuation of this idea, on the other hand, MongoDB also absorbed the memcached of things, in advance to apply for a memory area and file area, the memory address and physical address to correspond, It can be very high speed, which is one of the reasons MongoDB consumes memory and disk quite a lot.

  

III) MONGODB application range

  1:mongodb and traditional Database integration:

Id user_id Title Content Time
1 Tom Article title Article content Time

  In the table above, if the content is an article containing thousands of words, the content of the field is usually dropped into MongoDB, and then put in the MongoDB ID.

2:mongodb replaces traditional databases:

In situations where things are not demanding, and systems that allow partial errors, you can use MongoDB instead of traditional databases, such as forums, blogs, and other systems, for example, a chestnut:

Blog someone published an article that MongoDB stores as follows:

  

> Db.article.insert ({"title": "Test article", "Content": "Test Contents", "Time": "17822455", "UID": "1""ninserted": 1 }) > db.article.findOne (); {        " _id ": ObjectId (" 546168c9573c0742d8be1544 "),        " title ":" Test Article ",        " content ":" Test Content ",         "Time": "17822455",        "UID": "1"}

  Now one person commented on this article, as follows:

  

>varArticleinfo = Db.article.findOne ({"_id": ObjectId ("54616db1d92589121def0c70"))});>Articleinfo; {        "_id": ObjectId ("54616db1d92589121def0c70"),        "title": "Test article",        "Content": "Test Contents",        "Time": "17822455",        "UID": "1"}> articleinfo.commentary={"UID": "2", Info: {"Content": "This article is good", "Times": "145881444"}}; {        "UID": "2",        "Info" : {                "Content": "This article is good",                "Times": "145881444"        }}> db.article.update ({"_id": ObjectId ("54616db1d92589121def0c70"))},articleinfo); Writeresult ({"Nmatched": 1, "nupserted": 0, "nmodified": 1 })> Db.article.findOne ({"_id": ObjectId ("54616db1d92589121def0c70"))}); {        "_id": ObjectId ("54616db1d92589121def0c70"),        "title": "Test article",        "Content": "Test Contents",        "Time": "17822455",        "UID": "1",        "Commentary" : {                "UID": "2",                "Info" : {                        "Content": "This article is good",                        "Times": "145881444"                }        }}>

  Now another person commented on it as follows:

So MongoDB's storage structure becomes this:

  

> db.article.update ({"_id": ObjectId ("54617115d92589121def0c72")}, {"$push": {"Commentary": {"UID": 3,info: {" Content ":" I also this article good "," Times ":" 1444 "}}}}); Writeresult ({"Nmatched": 1, "nupserted": 0, "nmodified": 1 })> Db.article.findOne ({"_id": ObjectId ("54617115d92589121def0c72"))}); {        "_id": ObjectId ("54617115d92589121def0c72"),        "title": "Test article",        "Content": "Test Contents",        "Time": "17822455",        "UID": "1",        "Commentary" : [                {                        "UID": 2,                        "Info" : {                                "Content": "This article is good",                                "Times": "1444"                        }                },                {                        "UID": 3,                        "Info" : {                                "Content": "I also this article is good",                                "Times": "1444"                        }                }        ]}>

  Thus, if there are comments, continue to add to the ok,mongodb of this storage is at a glance, scalability is very strong, if not able to implement data consistency in the code processing, then it is good to use back relational database, in this kind of transactional not strong occasions, Using MongoDB can be a replacement for relational databases.

(iv) MongoDB use

  As a result of using logback to process logs, I have to write a lot of shell scripts, various awk processing text analysis user behavior dropped into the postgres, may not be the home technology, but they can come up with the things that are these, So in this project resolutely decided to use MongoDB as a log analysis system. If it is not distributed, using NoSQL is not worth the code word too hard.

  

Original The use of MongoDB in the system

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.