问题
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