1

我想创建一个简单的社交应用程序来测试 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,这是个好主意吗?

你有什么想法吗!非常感谢

4

1 回答 1

-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
    });
于 2015-11-14T07:04:50.950 回答