D
D
driverx182019-12-29 23:26:10
Database
driverx18, 2019-12-29 23:26:10

Why use relational subd for this situation?

I am reading a book on MongoDB, I see that the author gives an example: in order to display an article on a site using RDBMS, you need to have a database with tables: posts, authors, comments, tags, posts_tags, etc. All these tables are joined, and on large volumes we sacrifice the time to return the result, while Mongo can return the desired result with one document and store the data like this:

{
"title”: “Title of post”,
“comments”: [

],
“author”: “Author’s name”
...
}

In principle, in this case, it’s really not clear to me why an RDBMS with a large number of joins is needed in this situation, if everything is so easy with mongo. Earlier when I did the news section, I came to the RDBMS paths.
I would like to know what is the point of using mysql in this situation, and what is the minus of using nosql, otherwise only pluses are described in the book

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xfg, 2020-12-30
@driverx18

If there are an unlimited number of comments on an article, then storing data in this way is a bad idea. In mongodb, by default, a document cannot exceed 16 mb, but even without such a limit, this would result in a large amount of data being read into memory at one time. In this case, the data should be modeled in the same way as in the RDBMS.
There is a CAP theorem and you need to choose the type of database based on which 2 of the 3 properties are more important to you. RDBMSs give consistency and availability (CA) but sacrifice the ability to partition such a base, nosql solutions go the other way and sacrifice consistency in favor of availability and partition tolerance (AP). Data consistency in such systems is achieved using the Saga pattern instead of ACID.
In general, NoSQL is about projects whose data does not fit within a single server, and not about how to model this data. Nested documents in mongodb are more of a product of its architecture that is used as a marketing ploy rather than a solution that will be used everywhere. In the vast majority of cases, documents will refer to each other, just as it happens in RDBMS.
For a project with tiny amounts of data, it is more logical to choose an RDBMS and thereby greatly simplify your life. But in general, how NoSQL is used, data is sharded, and how data consistency is achieved in the absence of ACID is desirable to know, at least in general terms.
The worst thing is to choose a database and use it incorrectly, as an example of a document with nested comments, given their infinity in mongodb. We write a script that generates a trillion comments on an article, and then ask us to issue this article and the site goes offline. It's good that mongodb has foolproofing.

B
bkosun, 2020-12-30
@bkosun

One of the main advantages of relational databases is ACID (Atomicity) compliance:
Relational databases are suitable for data whose structure does not change often (your example).
https://ru.wikipedia.org/wiki/ACID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question