【问题标题】:Develop Database Schema for Notify like facebook像 facebook 一样为 Notify 开发数据库模式
【发布时间】: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


【解决方案1】:
router.post('/index/likestatus', function(req, res, next) {
    // Get form values   
    var username = req.user.username; //get the username from the sessions get current username who is login 
   var name = req.user.name; //same as above line this time get name of user
    var like = {
             "name" : name,
            "username": username
            };// my like is embedded to every status or post store who like this status

        Status.update({
                "_id": req.body.iid //this is status id or post id ...replace status with post in yours case 
            },
            {
                $push:{
                    "likes": like
                }//this $push save the newlike in collection 
            },
            function(err, doc) {
                if(err) {
                    throw err
                } else {
var newnotification = new notification
({postid:req.body.iid,,type:'like',uid:req.user.username,link:'yourlocalhost/'+post_id}).save(function (err) {
                console.log(username+' has posted a new status');
                    res.send({status:'success'});
                }
            }
        );//this save function save new notifications for a user the collection is similar to your req.body.iid is get from form u submit and its status id ,uid:req.user.username you store username in uid as i say username is _id or primary key
    });

【讨论】:

  • 你能解释一下对应的问题吗?即使它是有效的解决方案,没有解释也没有任何意义
  • 对不起,我回答它,因为我认为你知道一些 nodejs 和 mongodb...我用 cmets 编辑答案,这对你很重要,先生
猜你喜欢
  • 2016-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-22
  • 1970-01-01
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
相关资源
最近更新 更多