【发布时间】:2021-04-27 19:07:46
【问题描述】:
我的模特:
const userSchema = mongoose.Schema({
_id: mongoose.Types.ObjectId,
name: { type: String, required: true, maxlength: 32, trim: true },
email: { type: String, required: true, trim: true, unique: true },
words: [Object]
}
, { timestamps: true }
)
如果 word 数组不存在,我想添加一个对象,否则更新 repeat_count 的值。
这是我要添加的词对象:
var word = { word : "hello" , repeat_count : "12" }
有没有内置函数可以做到这一点?
【问题讨论】: