我在MongoDB-Nodejs环境中。我有两类用户,即
Normal User: This class Users can Only post 1 Blog per day.
Special Class User: This User can Post the Blog 5 times a day.我的数据库结构是这样的:
{
"_id" : ObjectId("7f5797bb5000e4f1c9c85d39g"),
"userid" : "1",
"Post" : 'Hello world',
"Heading" : 'Testing',
"createdate" : ISODate("2018-02-16T06:35:33.364Z"),
"__v" : 0
}... upto 100 entries现在,为了完成这个任务,我有一个user类。
我在nodejs代码上执行的操作类似于if else条件。
if(user == 'normal') {
//Calculating the length of data
if (data.length < 5){
Value save function execute which can do the entry on collection
} else {
console.log('Your daily Limit Exceed);
}
} else {
if (data.length < 1){
Value save function execute which can do the entry on collection
} else {
console.log('Your daily Limit Exceed);
}
}现在这些东西对我来说完全没问题。主要的问题是,超过限制的特定用户将总是被禁止或无法在集合上进行条目。
我想要这个逻辑,但只有一天。第二天,相同的用户可以根据类别标准发布博客,即限制1或5。
有人建议我如何做到这一点吗?我知道有一些时间戳标准可以让我们做到这一点。但是没有得到确切的解决方案
任何帮助都是非常感谢的
发布于 2018-02-16 20:51:40
只获取在当前日期创建的帖子并比较结果长度。我将使用moment().startOf('day').toDate()使用moment.js来创建日期的开始
db.collection('posts')
.find({createdate: {$gte: moment().startOf('day').toDate()}})
.toArray(...)https://stackoverflow.com/questions/48825409
复制相似问题