开发数据库架构通知像Facebook [英] Develop Database Schema for Notify like facebook

查看:133
本文介绍了开发数据库架构通知像Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个简单的社交应用来测试mongoDB的性能
例如我发布一个状态你好每个人,有一个美好的一天
我的社交发送通知,只要其他用户喜欢 ,评论,分享

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

}

哦,有千个通知,每天都创建一个milion通知
为A,B, C也喜欢你的评论,C,D,E也在你的帖子中发表评论,我不认为每一个通知,我们创建一个新的分别项目。
然后我有一个想法

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

我添加3个字段用于这样的帖子文件

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

每当用户在我的帖子中发表评论时,标记comment_notify变为1,告诉我,我的帖子有新评论

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

但是文件的大小限制为16MB,这是个好主意?

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

你有什么想法吗谢谢这么多

Do you have any idea for it!thank so much

推荐答案

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

这篇关于开发数据库架构通知像Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆