简体   繁体   English

MongoDb:建立可能超过百万文档的多对多关系

[英]MongoDb: Establishing a Many-To-Many relation that may exceed millions of documents

I am building a social media app in which each user can follow an indefinite number of other users.我正在构建一个社交媒体应用程序,其中每个用户都可以关注无限数量的其他用户。
According to this website , there are two ways of building this relation in the code.根据这个网站,有两种方法可以在代码中建立这种关系。 Either by Two Way Embedding or One Way Embedding.通过双向嵌入或单向嵌入。

One Way Embedding is to be used if the relation is asymmetric.如果关系是不对称的,则将使用一种方式嵌入。 Ie: Model A can have a huge number of Model B whereas Model B has a very limited number of Model A.即:模型 A 可以有大量的模型 B,而模型 B 的模型 A 数量非常有限。

Two Way Embedding is to be used if the relation is somewhat symmetric.如果关系有些对称,则将使用双向嵌入。 Ie: Model A has almost as many Model B as Model B has model A.即:模型 A 的模型 B 几乎与模型 B 的模型 A 一样多。
This is in order not to exceed the size limit of a document.这是为了不超过文档的大小限制。
Check the linked website for more details.查看链接的网站了解更多详情。

The problem with my project is the relation is between the model and itself.我的项目的问题是模型与其本身之间的关系。 In other words, the model is User and it can follow other Users.换句话说,模型是用户,它可以关注其他用户。

So, a user will follow a big number of other users, the size of his document might exceed the size limit.因此,一个用户会关注大量其他用户,他的文档大小可能会超过大小限制。
So the question is:所以问题是:
Should I implement the Many-To-Many relation without using the embedding approach?我应该在不使用嵌入方法的情况下实现多对多关系吗?

为用户之间的链接使用单独的集合,从该集合中引用两个用户 ID。

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

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