如何设计 mongodb collection
How to design the mongodb collection
我的 collection 场景是:
用户 A 可以阻止其他用户,其他用户也可以阻止用户 A,即多对多关系。
但我的问题是如何设计用户 class.
只需将所有被阻止的用户放入某种列表或向用户 class 嵌入一个阻止 class。
可能的解决方案:
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
}
class哪一个最适合求婚?
感谢任何帮助。
更新
用户A不喜欢用户B、C等会在同一个群里,可以拉黑他们。
也许用户 B 既不希望用户 a 是同一组,这样他们就可以互相阻止。当我显示可能的用户和组列表时,它们彼此不可见,例如用户 A 不能选择用户 B,反之亦然。
一个用户应该有一个他屏蔽的用户的ID列表,这样你就可以用最少的提供的信息识别被屏蔽的用户,你不必担心冗余信息不一致。
嵌入整个User会导致递归爆炸,因为嵌入的被屏蔽的用户也可以有嵌入的用户,依此类推
public class User {
String id;
String username;
String password;
String email;
List<String> blockedUserIds;
//getter and setters
}
我的 collection 场景是: 用户 A 可以阻止其他用户,其他用户也可以阻止用户 A,即多对多关系。 但我的问题是如何设计用户 class.
只需将所有被阻止的用户放入某种列表或向用户 class 嵌入一个阻止 class。
可能的解决方案:
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
}
class哪一个最适合求婚?
感谢任何帮助。
更新
用户A不喜欢用户B、C等会在同一个群里,可以拉黑他们。 也许用户 B 既不希望用户 a 是同一组,这样他们就可以互相阻止。当我显示可能的用户和组列表时,它们彼此不可见,例如用户 A 不能选择用户 B,反之亦然。
一个用户应该有一个他屏蔽的用户的ID列表,这样你就可以用最少的提供的信息识别被屏蔽的用户,你不必担心冗余信息不一致。
嵌入整个User会导致递归爆炸,因为嵌入的被屏蔽的用户也可以有嵌入的用户,依此类推
public class User {
String id;
String username;
String password;
String email;
List<String> blockedUserIds;
//getter and setters
}