如何限制用户内容帖子

时间:2017-12-25 11:45:43

标签: javascript node.js mongodb

我想对每个用户进行限制,每天只发布5次内容。

{
    _id: 5a3a67b102d9d926f8cd66b8
    groupname: 'Testing',
    member: [
        {userid:123},
        {userid:456},
        {userid:789},
        {userid:879}
    ]
}

实际上,我有一种方法,即

First create the column which may be named as entries_counter, after that every entry did successfully, we have to increment the counter till it 5. After 5 we will stop doing the entries. And every day at night or some time format we will update the entries_counter value to 0 through CronJob.

建议我使用一些最佳或预定义/预建的方法来处理这些类型的情况。任何帮助都是赞赏的。

1 个答案:

答案 0 :(得分:1)

发布后,执行查询,计算用户在过去24小时内创建的帖子数。如果它超过你的MAX_POSTS_ALLOWED,不要允许它。

在我看来,您不应该明确跟踪每天创建的帖子数量。或者您需要每天清除该列。