2013-02-21 56 views
1

我想創建一個簡單的社交應用程序來測試mongoDB的性能 例如,我發佈狀態「Hello every body,have a good day」 我的社交發送通知時,其他用戶「喜歡」,‘評論’,‘共享’開發用於通知的數據庫模式,如facebook

"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,那是個好主意嗎?

你有任何的想法!感謝這麼多

+0

你應該嘗試一下,看看有什麼效果最好,尤其是當你有興趣測試的MongoDB的性能。 – WiredPrairie 2013-02-21 12:01:23

+0

我可以看到第二個設計的一個問題就是了解何時出現新事件。你知道誰對帖子發表了評論,但你不知道誰剛發表評論,以及他們是否在回覆原始海報時發佈了另一個回覆,但這一切都取決於你希望狀態如何真正起作用 – Sammaye 2013-02-21 12:21:11

+0

是的,你是對的,如果有一位用戶在帖子中再次發表評論時會遇到麻煩,我想我們需要添加一個字段來標記帖子中最後一條評論的人,感謝您的建議 – 2013-02-21 12:45:16

回答

0
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 
    }); 
+0

您能解釋一下與問題相對應嗎?即使它工作的解決方案它沒有任何意義沒有解釋 – WoodChopper 2015-11-14 07:23:31

+0

對不起,我回答它,因爲我認爲你知道一些nodejs和mongodb ...我編輯答案與評論每一行,這是重要的,你先生 – user3720522 2015-11-15 03:54:44