I need to increment the counter field as long as it's less than 500 otherwise reset the counter to zero.
Here is my snippet:
StudentInfo.findOneAndUpdate(
{ studId: SID },
**{ $inc: { counter: 1 } },**
(err, studInfo) => {
if (err || !studInfo) {
console.log(err);
} else {
console.log(${JSON.stringify(studInfo));
}
},
);
How can I do it in a single update call?