Initial knowledge of NoSQL NoSQL database NoSQL Database Basics _mongodb

Source: Internet
Author: User

Do a year's freshman year project, for relational database structure or some understand, sometimes still feel that the two-dimensional table is not very comfortable. After reading an article, there is a preliminary understanding of NoSQL (Https://keen.io/blog/53958349217/analytics-for-hackers-how-to-think-about-event-data). This article is written very well, indeed written out in the actual situation of the "NoSQL" and use the Minecraft for analysis, but may not be comprehensive. For example, only mentioned in the article, Entity data with relational type How to save, event data with NoSQL How to save, I want to borrow this article, to analyze the event type of data original relational database is how to save data, and then the two storage methods to do a comparison, It is a supplement to the original.

For this kind of death, there are two data, one is about Creeper explosion, one is falling into magma. If you had to use a relational two-dimensional table database, I would store it like this. (If you do not know what kind of data, you can first look at the following NoSQL storage methods, so that looks more clear.) )

This data can be said to be a more complex database design situation, because it contains two cases (of course, more than two cases, it will produce more structure), different circumstances of the data table structure is different, which is very troublesome. Our general solution is to design four tables that take advantage of relational database relationships. The following four forms are designed. (I'll abbreviate it here)

First table

ID #首先用于关联, the primary table needs to have an ID, this is not the difference, because NoSQL will also have a _id preset
  timestamp #所有共同部分就可以存在一张表中.
  cause
  player_uid
  player_experience
  player_age    #对于player_inveneory_id Because this is an array of arbitrary lengths, Can only be saved in another table.

Second table (for preservation of the death of Creeper death)

ID #这是这张表的id以后可以跟别的表格关联
  mid #用于关联主表
  enemy_type
  enemy_power
  enemy_distance
  enemy_age

The third table (for the preservation of the death of Lava death)

  ID #这是这张表的id以后可以跟别的表格关联
  mid #用于关联主表
  place_x
  place_y
  place_z 

Table four (for saving player_inveneory)

  ID #这是这张表的id以后可以跟别的表格关联
  mid #用于关联主表
  inveneory

This is the case for the relational database that has the different structure of the event storage rules, and then stored as follows (I do not draw the table)

1.
  ID  timestamp          cause    player_uid    player_experience  player_age
  1   "2013-05-23t1 : 50:00-0600 "  " creeper "  " 99234890823 "   8873729        228    
  2   " 2013-05-24t23:25:00-0600 "  "Lava"   "99234890823"   88737

2.
  ID  mid   enemy_type  enemy_power  enemy_distance  enemy_age
  1   1    "Creeper"   . 887      3.34       . 6677

3.
  ID  mid  place_x  place_y  place_z
  1   2   45.366   -13.333  -39.288

4.
  ID  Mid  inveneory
  1   1   "Diamend Sword
  2   1   " torches "
  3   2   " Stone 

So far, we've saved these two event data with a relational database. (Good trouble, yes!) )

We look at the NoSQL storage method, because each data is not limited by the field (column name), can be directly saved, without the table. (such as JSON format)

#第一条数据
{
  "timestamp": "2013-05-23t1:50:00-0600",
  "cause": "Creeper",
  "enemy": {
    "type": " Creeper "Power
    ":. 887
    "Distance_from_player": 3.34
    "Age":. 6677
  },
  "Player": {
    "UID": " 99234890823 ",
    " experience ": 8873729," Age
    ": 228,
    " inveneory ": [" Diamend sword "," torches "]
  }
}
#第二条数据
{
  "timestamp": "2013-05-24t23:25:00-0600",
  "cause": "Lava",
  "place": {
    x:45.366
    y:-13.333
    z:-39.288
  }
  "Player": {
    "UID": "99234890823",
    "experience": 88737,
    "Age":
    "inveneory": ["Stone"]
  }
}

Here we analyze the benefits of NoSQL for this type of data storage

1. The first is to integrate the decentralized table structure so that the data should be together.
This is like the C language to open multiple array storage or a structural array of differences, put some relational data together is a natural idea of human beings, of course, it will make people more comfortable, and can improve the relevance and ease of upgrade extension.

2. Storage becomes convenient
Let's consider how we can store the data.
For two-dimensional table databases:
1. Analysis of data is of that type
2. Store the main table data and get the return ID
3. Branch, plus the primary table ID in different cases to the lava or Creeper table to store data
4. Open loop, insert multiple records into the Inveneory table
This is just a brief, but also consider the multiple table operations when the data rollback problem, actually write about 30 lines, then the error may be greatly improved.
For NoSQL types
One word:

Insert (data); #伪码

In fact, if you think about it, the original relational database will be just as troublesome when you take the data.

3.NoSQL is more conducive to the dynamic generation of storage, a lot of flexibility, at least we can store data in the design of the database (although may be better in advance design)

Of course, if the storage is not the event or similar to such data is another matter, the two-dimensional table has a lot of its own advantages. The above is some of my personal analysis, of course, there are many commonly accepted views, the following are some generally agreed on the two database models of the pros and cons of analysis, I also basically agree.

Relationship Advantage:
1. Transaction processing---maintaining consistency in data;
2. Due to standardization, the cost of updating the data is very small (the same field is basically one place);
3. You can perform complex queries such as join.

Relational disadvantage:
1. Expansion difficulties: Because of the existence of such a join table query mechanism, making the database in the expansion of the difficult;
2. Slow reading and writing: This kind of situation mainly occurs when the data quantity reaches a certain scale, because the relational database system logic is very complex, makes it very easy to have the deadlock and so on concurrency problem, therefore causes its reading and writing speed to fall very serious;
3. High cost: The license price of enterprise database is very alarming, and it is rising with the scale of the system.
4. Limited support capacity: Existing relational solutions are not able to support such a large number of Google data storage;

NoSQL advantages, mainly reflected in the following points:
1. Simple extensions: A typical example is Cassandra, whose architecture is similar to the classic Peer-to-peer, so it can be expanded by easily adding new nodes;
2. Fast reading and writing: The main example has Redis, because of its simple logic, and pure memory operation, so that its performance is very good, single node can handle more than 100,000 times per second read and write operations;
3. Low cost: This is a common feature of most distributed databases, because it is mainly open source software, there is no expensive license cost;

NoSQL database still has a lot of deficiencies, common mainly have the following several:
1. Do not provide support for SQL: If you do not support the industry standards such as SQL, you will have a certain learning and application of migration costs;
2. The supported features are not rich enough: existing products offer less functionality, most NoSQL databases do not support transactions, and do not provide additional functionality like MS SQL Server and Oracle, such as BI and reports;
3. The existing product is not mature: Most products are still in the start-up period, and relational database for decades of perfect;

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.