我目前在我的项目中使用过猫鼬,这是我的架构:
const mongoose = require('mongoose');
const classSchema = mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
consultant: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Consultant',
required: true,
},
faculty: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Faculty',
required: true,
},
startYear: {
type: String,
required: true,
},
currentSchoolYear: {
type: String,
required: true,
},
currentSemester: {
type: String,
required: true,
},
classname: {
type: String,
required: true,
unique: true,
},
classSize: {
type: Number,
required: true,
},
warnedLength: {
type: Number,
required: true,
},
});
const Class = mongoose.model('Class', classSchema);
module.exports = Class;
如您所见,我有2个属性分别是classSize
和warnedLength
是Number。现在,我想创建一个函数,当我单击客户端上的按钮时,classSize
和warnedLength
的值将自动减小1。无论如何,有这样做吗,非常感谢您的帮助我出去,对我来说意义重大,祝你有美好的一天