我必须从各种社交媒体中保存用户的不同个人资料。例如
用户可能拥有1个facebook和2个Twitter个人资料。如果我保存每个配置文件
它作为一个新文档插入不同的集合,如Facebook和Twitter是一个集合,我将如何将此文档与另一个相关联。
我在mongodb中使用了点符号。如果我涉及同一用户的脸书和推特个人资料意味着
它很容易获取记录。我如何设计架构?还how would i avoid duplication
?是否有可能使用facebook id
twitter id是唯一的吗?我是mongoDB
的新手。我如何加入来自不同馆藏的文件
答案 0 :(得分:1)
这是一个ruby实现,但希望你能够将模式逻辑转换为java代码。
class User
has_one :facebook_profile
has_one :twitter_profile
end
class TwitterProfile
belongs_to :user
end
class FacebookProfile
belongs_to :user
end
您可以对集合强制执行唯一索引,如下所示:
db.twitter_profiles.ensureIndex({user_id: 1 }, {unique: true})
db.facebook_profiles.ensureIndex({user_id: 1}, {unique: true})
您可以在用户级别使用您想要强制唯一性的任何字段。
希望有所帮助。