Javascript Mongoose会自动减少数字类型的字段

Javascript Mongoose会自动减少数字类型的字段,javascript,database,mongoose,automation,backend,Javascript,Database,Mongoose,Automation,Backend,我目前在我的项目中使用了mongoose,这是我的模式: const mongoose = require('mongoose'); const classSchema = mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, consultant: { type: mongoose.Schema.Types.ObjectId, ref: 'Consultant', required: true, },

我目前在我的项目中使用了mongoose,这是我的模式:

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;

如您所见,我有两个属性是
classSize
warnedLength
是Number。现在我想做一个函数,当我从客户端单击一个按钮时,
classSize
warnedLength
的值将自动减少1。不管怎样,还是要这样做的,非常感谢你的帮助,这对我来说意义重大,祝你愉快

你可以使用
$inc:{classSize:-1,warnedLength:-1}
非常感谢你,如果你是越南人,它很有效:“Em cảmơn anh rất nhiều、 埃姆斯ử 瓦诺什ạy thánh công”