Develop Database Schema for Notify like facebook

不打扰是莪最后的温柔 提交于 2019-12-23 03:40:37

问题


I want to create a simple social app to test performance of mongoDB For example I post a status "Hello every body, have a good day" my Social send notifications whenever others user "like","comments","share"

"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

the first time, I try to design it like this

notify_post
{
    "post_id":"",
    "link" : "",//link to post
    "type": ""//like comment or share
    "u_id": // the Id of user that like, comment,...etc

}

ohh, there are thousand notifications, even milion notifications are created every day for exam A, B , C also like your comment, C,D,E also comment in your post , I don't think with each notify like that we create a new respectively item. Then I have a idea

I add 3 field for post document like that

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...
 }

whenever a user comment in my post the flag "comment_notify" is turn to 1 to tell me that my post has a new comment

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

but a size limit of document is 16MB, that is good idea?

Do you have any idea for it!thank so much


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


来源:https://stackoverflow.com/questions/14997828/develop-database-schema-for-notify-like-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!