簡體   English   中英

為像Facebook這樣的通知開發數據庫架構

[英]Develop Database Schema for Notify like facebook

我想創建一個簡單的社交應用程序來測試mongoDB的性能例如,當其他用戶“喜歡”,“評論”,“分享”時,我發布狀態為“大家好,祝你有美好的一天”,我的社交網站會發送通知

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

您有任何想法嗎?非常感謝

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM