草庐IT

totalAttempts

全部标签

node.js - 基于 Mongoose 中另外两个字段的第三个字段的计算

我在Mongoose模型上有2个字段:totalAttempts和totalRight。我打算根据它们计算准确度。totalAttempts:{type:Number,default:1},totalRight:{type:Number,default:1}这就是我所做的[它不起作用]accuracy:{type:Number,required:function(){return(this.totalRight/this.totalAttempts*100).toFixed(2)}}此外,如果我不为准确性设置默认值,我会收到错误消息:ERROR;Whilecreatingnewques