node js mongoose schema

时间:2016-02-14 20:26:08

标签: node.js mongoose

我有一个简单的mongoose架构。但是约束不能正常工作。

if ([[NSUserDefaults standardUserDefaults] integerForKey:@"showAd"] % 3 == 0) {
 [RevMobAds startSessionWithAppID:@ID
                  withSuccessHandler:^{
                      [[RevMobAds session] showFullscreen];
                  } andFailHandler:^(NSError *error) {
                  }];
}

我的架构有什么问题?

1 个答案:

答案 0 :(得分:0)

我不确定你能用Mongoose这样做,但这应该有效:

var p = new Schema({
  deadline: {
    type: Date,
    required: [true,'Deadline is required'],
    validate: [dateValidator, 'Deadline validation error']
  }
});

// function that validate the min and max value of a deadline
function dateValidator(value) {
  var min = new Date(+new Date + 20*60000).getTime();
  var max = new Date(+new Date + 365*24*60*60000).getTime();
  var deadline = new Date(value).getTime();

  return min < deadline && deadline < max;
}