【问题标题】:How to design the mongodb collection如何设计mongodb集合
【发布时间】:2015-02-04 10:02:04
【问题描述】:

我的收藏场景是: 用户 A 可以阻止其他用户,其他用户可以阻止用户 A,即多对多关系。 但我的问题是如何设计 User 类。

只需将所有被阻止的用户放在某种列表中或将 Block 类嵌入到 User 类中。

一个可能的解决方案:

public class User
{

 String id;
  String username;
String password;
String email;
List<User> blockedUserEmails;
//getter and setters
}

或者

public class User
{

String id;
 String username;
String password;
String email;
//getter and setters

 List<String> blockedUserEmailsInAList;
 }

或者

  public class User
  {

String id;
String username;
String password;
 String email;

@Embedded
List<Blockee> blockedUserId;

//getter and setters
}

哪一门课最适合这个提议?

感谢任何帮助。

更新

用户 A 不喜欢用户 B、C 等将在同一个组中,并且可以阻止他们进入该组。 也许用户 B 不希望用户 a 是同一个组,所以他们可以互相阻止。当我显示可能的用户和组列表时,它们彼此不可见,例如用户 A 不能选择用户 B,反之亦然。

【问题讨论】:

  • “最佳”的标准是什么?
  • 我只需要一些与最多 500 个用户一起工作的解决方案。 (使用 Spring MVC)
  • “运作良好”的标准是什么?请告诉我们对您而言是好还是坏的解决方案。
  • 您需要将被阻止的用户列表用于什么目的?您是否只需要用户已阻止的人员的电子邮件地址列表?
  • 请检查更新。我不明白你所说的标准是什么意思。请你帮我解释一下吗?

标签: mongodb collections


【解决方案1】:

一个用户应该有一个被他屏蔽的用户的ID列表,这样你就可以用最少的信息来识别被屏蔽的用户,你不必担心多余的信息会不一致。

嵌入整个User会导致递归爆炸,因为嵌入的阻塞用户也可以有嵌入的用户,以此类推。

public class User {
  String id;
  String username;
  String password;
  String email;
  List<String> blockedUserIds;
  //getter and setters
}

【讨论】:

  • 感谢您的回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-30
  • 2020-09-27
  • 1970-01-01
  • 2014-09-14
  • 2018-06-09
  • 2012-03-08
  • 1970-01-01
相关资源
最近更新 更多