【发布时间】:2013-02-21 08:41:11
【问题描述】:
我想创建一个简单的社交应用来测试 mongoDB 的性能 例如,我发布了一个状态“大家好,祝你有美好的一天” 每当其他用户“喜欢”、“cmets”、“分享”时,我的社交都会发送通知
"A like your post" -> create a new notify
"B like your post" -> create a new notify
"C comment in your post" -> new no
"D comment in your post" -> new no
第一次尝试这样设计
notify_post
{
"post_id":"",
"link" : "",//link to post
"type": ""//like comment or share
"u_id": // the Id of user that like, comment,...etc
}
哦,有上千条通知,甚至每天都会创建上百万条通知 对于考试 A、B、C 也喜欢您的评论,C、D、E 也在您的帖子中发表评论,我不认为每个通知都像我们分别创建一个新项目。 那我有个主意
我为这样的发布文档添加了 3 个字段
post
{
"title":""
"content" :""
"like":[]//
"like_notify" : //0 or 1
"comment" [uid,uid]
"comment_notify" : //0 or 1
"share": [uid,uid]
"share_notify" //0 or 1
comment //rest...
}
每当用户在我的帖子中发表评论时,“comment_notify”标志就会变为 1,告诉我我的帖子有新评论
like "A comment in your post",
then C,D,E also comment in my post ,notify will be like that
"E,D and 2 others user also comment in your post"
"like" and "share" is so on
但是文档的大小限制是 16MB,这是个好主意吗?
你有什么想法吗!非常感谢
【问题讨论】:
-
您应该尝试一下,看看哪些性能最好,尤其是当您对测试 mongodb 的性能感兴趣时。
-
我可以看到第二种设计的一个问题是理解新事件何时出现。你知道谁在帖子上发表了评论,但你不知道谁刚刚发表了评论,以及他们是否发布了另一个回复来回复原始发帖人,但这一切都取决于你希望状态如何真正发挥作用
-
是的,你是对的,如果一个用户在帖子中再次评论会很麻烦,我认为我们需要再添加一个字段来标记帖子中的最后一个评论,谢谢建议
标签: mongodb database-design social database