猫鼬会自动减少数字类型的字段

时间:2020-11-01 17:57:23

标签: javascript database mongoose automation backend

我目前在我的项目中使用过猫鼬,这是我的架构:

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个属性分别是classSizewarnedLength是Number。现在,我想创建一个函数,当我单击客户端上的按钮时,classSizewarnedLength的值将自动减小1。无论如何,有这样做吗,非常感谢您的帮助我出去,对我来说意义重大,祝你有美好的一天

0 个答案:

没有答案