Is there the way to combine Model.findByIdAndUpdate
and Model.increment()
which increments mongoose native versionKey? Or Model.update()
and any incrementation of __v
?
This code doesn't increment __v
Station.update({ _id: req.params.id },
{ $set: req.body, $inc: { __v: 1 } },
{ multi: false }, callback);
but increments any custom Number
field:
Station.update({ _id: req.params.id },
{ $set: req.body, $inc: { count: 1 } },
{ multi: false }, callback);
So far I've found only one way to increment __v
:
Station.findById(req.params.id, function (err, station) {
station.increment(); // this increments __v
station.save(req.body, callback)
})