简体   繁体   English

关系的集合。 NoSQL 与 SQL

[英]Collection of relations. NoSQL vs SQL

I understand the difference between NoSQL and SQL, but I still have a small question.我了解 NoSQL 和 SQL 之间的区别,但我还有一个小问题。 It's about a many-to-many relationship.这是关于多对多的关系。 I know that if I need such a relationship, I should use relational databases.我知道如果我需要这样的关系,我应该使用关系数据库。 However, in my case, I prefer to use document-oriented databases, because I need to store a large number of documents, much larger than the number of entities with relationships.但是,就我而言,我更喜欢使用面向文档的数据库,因为我需要存储大量文档,远大于具有关系的实体的数量。

So, I need to implement user groups.所以,我需要实现用户组。 Of course, users can exist outside of groups, therefore they are documents of a separate collection.当然,用户可以存在于组之外,因此它们是单独集合的文档。 In addition, one user can be in several groups, which means this is a real many-to-many relationship.此外,一个用户可以在多个组中,这意味着这是一个真正的多对多关系。 People say that “mongo-way” is to make a user with a list of links to groups and a group with a list of links to users, but this option doesn't suit me, because sometimes I need to display a list of groups without displaying a list of the group users, which can take most of the document.人们说“mongo-way”是让一个用户有一个组链接列表和一个组有一个用户链接列表,但是这个选项不适合我,因为有时我需要显示一个组列表不显示组用户列表,这可以占用大部分文档。

As an alternative, I want to use the traditional “relationship tables” that are used for many-to-many relationships in relational databases.作为替代方案,我想使用用于关系数据库中多对多关系的传统“关系表”。

So my question is, what is the practical difference between using such tables in mysql or in mongodb?所以我的问题是,在 mysql 或 mongodb 中使用这些表有什么实际区别? As far as I know, there are no foreign keys in mongodb, but does that really prevent me from doing something like this ?据我所知,mongodb 中没有外键,但这真的阻止我做这样的事情吗? I see the problem only in the fact that you can not get rid of the required _id and its indexes.我只看到问题在于您无法摆脱所需的_id及其索引。 By the way, in this case, should I create indexes for the UserId and GroupId fields?顺便说一句,在这种情况下,我应该为UserIdGroupId字段创建索引吗?

Or maybe I should give up the idea to fit everything into one database and use SQL and NoSQL together in one project?或者也许我应该放弃将所有内容放入一个数据库并在一个项目中一起使用 SQL 和 NoSQL 的想法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM