Build a vibrato-like short video APP from scratch--Back-end message database storage storage selection and MongoBD overview

Table of contents

Message data storage warehousing selection

Important data storage selection

Storage selection of non-important databases

Overview of MongoDB

MongoDB Terminology

MongoDB data structure


Message data storage warehousing selection

Important data storage selection

       Important data For example, let’s give an example here, such as some order data, and some prices are all in the e-commerce system

of. There are also some merchants and shops, and some related important information, such as these information, are generally put in the database

It is 100% necessary to save. While saving, then maybe we will combine some other middleware, and

There is or is some Nosql, let's say a cache. Or Es, save the relevant data again, and perform an accelerated inspection

So, in this way, our data can guarantee their important data. will not be lost because they are sure

will exist in our database.

Storage selection of non-important databases

        In addition to important data, there are some non-important data, such as those generated during our usual use.

There will be a lot of logs , and we will collect them . Because there are too many logs, too huge, it is impossible to put all

The logs are put in the database, so the logs are non-important data, even if they are all lost, there is nothing wrong with our entire system.

It doesn't matter.

        There is also snapshot data , what is a snapshot? For example, let’s say we placed this order in e-commerce, today I

Placed an order. For example, I bought a mobile phone for 5,000 yuan. After a while, the owner modified the mobile phone. For example,

Said to increase the price to 6000. When the order was purchased at that time, the product data in it will not change, so when we query

At this time, it is impossible to query our product table through multi-table association. Instead, he will have a snapshot table of commodities, and there will be a commodity in

A snapshot information generated at that time. So this information, it is a kind of temporary information data, when you go to Taobao or Beijing

When you go to the East, you will find the product data you purchased in the early days, and it will have a snapshot data at the beginning. after a while

Time, maybe after the data is cleaned up, it may disappear, there will be such a situation, this is a snapshot, or

Said that we usually send resumes. When you submit your resume on a recruitment website, when you submit it, it is actually a part of your resume information at that time.

A snapshot information, a resume sent before subsequent changes, its previous information will not follow your subsequent updates

Changes have been made instead, so these are all snapshot information.

        In addition, there are some message data . What is a message is generally some system messages that we send in the system.

interest and so on. This is some of the news we are going to get in touch with, and it will be involved in many websites and systems.

To some similar messages, the message is actually a kind of non-important data. It is dispensable, not completely lost, for our entire

The system is also no problem.

What does the news look like on our side?

        This is our news page. When some users comment on your video, some users follow you, and some users

I also replied to you, liked your comment, and liked your video. Correspondingly, all these message data can be entered here

The corresponding one is displayed here, which is actually our news. Messages and logs and snapshots, for these data

In terms of speaking, we can generally store it in Nosql, MongoDB or Es. On our side, we will take

Use a form to do a corresponding storage. So like logs, before our early days, we actually put

Go inside MongoDB. Nowadays, we basically put the collection of logs into ES in a unified way. In addition, there are

It is a snapshot data snapshot. Generally speaking, we will put it in MongoDB now. So, what we have in this chapter

What needs to be implemented, and what interacts with our persistence layer is MongoDB.

Overview of MongoDB

        Let's take a look at this MongoDB first, then for MongoDB, it is actually a Nosql database, that is, a non-guan

A system-type database can store node-level data. It is because it can store a kind of document data such as json, in fact, it

The data format will be very flexible, it is better than the database mysql, mariaDB. At the same time, it can also be

What about a database like mysqls and mariaDB, to share part of the traffic pressure. In fact, for some people who often have to read and write

data, it will be placed in memory. In this way, the concurrency performance for some hot data is quite high, so it is

It can improve the efficiency of the whole system. In addition, it does not support transactions itself. For some non-transactional data,

We can save it in it, and these data are often non-core data.

Generally speaking, if we can store some non-important data, but its one reading and writing has a relatively large concurrency, then

So we can store them in MongoDB. For example, in our own hazardous logistics transportation system

The GPS coordinates of the running track of the vehicle, as well as some dynamic indicators in the atmospheric monitoring and so on.

In addition, for MongoDB, it also provides a GridFS, which is more suitable for storing some small files, and

We can control the read permission of this interface by ourselves. It can go unrestricted. Then this point is also more advantageous

Potential, for us, generally speaking, face information and other such pictures. We can store them in the

Go inside MongoDB's GridFS.

MongoDB Terminology

Then let's take a look at a term in mongo db,

Here we mainly compare the database and MongoDB.

MongoDB data structure

Here are two json objects 

    It contains two json-objects, among which UserList is in mongodb, we just call it in a certain database

The collection in , which is a collection. In the database, it is actually a user table. In each of us actually

It can contain multiple json objects, that is, the curly braces, and a curly brace represents an object. in our mongodb

On the surface, it will be called a document.

        In addition, because it is actually a json data, mongodb is a Nosql database, so when we store data

Sometimes, one of its stored fields is not so rigorous . Suppose we are using a database now, there are currently three fields

For user ID, username and age, all the data of each row in the current table, in fact, it will contain these three

Attributes. If you don't fill it in, then a certain data is empty. But in mongodb, you can see

arrive. In our first object, it has only three attributes, and in the next object, it has an extra sex, that is to say

When its json data is stored, a certain attribute can have a value in it, and it exists in another object.

The current attribute is optional . Well, this is where using json in mongodb is more flexible. next is

The attribute column, the user ID, user name, age sex, etc., are actually columns, which correspond to our

Each row in a database table. In its mongodb, we call it filed, and this is our

A data structure for MongoDB.

Guess you like

Origin blog.csdn.net/m0_64005381/article/details/127685022