Answer the question
In order to leave comments, you need to log in
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”
...
}
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question