When using findOneAndUpdate
how can I add one to a value? In this case, I want to add 1 to the commandsUsed Object. Example Below:
await mongo().then(async (mongoose) => {
try {
await userSchema.findOneAndUpdate({
_id: author.id,
}, {
_id: author.id,
commandsUsed: //I want to add 1 to this Object
}, {
upsert: true,
})
CodePudding user response:
You can use findOne
then add the field, finally save it.
const doc = await userSchema.findOne({ _id: author.id })
doc.commandsUsed
doc.save();