我想创建一个简单的社交应用来测试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
}
哦,有一千个通知,甚至每天都会创建一个milion通知
对于考试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 :(得分: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
});