How to increment property's value and update for some time of period in mongoose?

孤街浪徒 提交于 2021-01-29 20:33:13

问题


I have a studentSchema in which there are pass property with default value 0(means that time student does not having any concession pass). When student make a request for the pass , if the admin accept that request then student will gets his pass and the value of pass property gets updated to 1(means now student has the pass ) . And also this pass only available for some days e.g.one or two months . after one month has been completed student needs to request for the new pass. **codeshareio link ** https://codeshare.io/a3jBL6 student model https://codeshare.io/5DOJXW student controller

const { ObjectId } = mongoose.Schema;

const studentSchema = new mongoose.Schema(
  {
    Fullname: {
      type: String,
      required: true,
      trim: true,
    },
    addmissionNumber: {
      type: String,
      required: true,
      trim: true,
      maxlength: 10,
      unique: true,
    },
    rollNo: {
      type: Number,
      required: true,
      trim: true,
      maxlength: 4,
    },
    email: {
      type: String,
      trim: true,
      required: true,
      unique: true,
    },
    pass: {
      type: Number,
      default: 0,
    },
  },

  { timestamps: true }
);

module.exports = mongoose.model("Student", studentSchema);

来源:https://stackoverflow.com/questions/65614871/how-to-increment-propertys-value-and-update-for-some-time-of-period-in-mongoose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!