mongoose increment code example
Example 1: mongoose increment sub document
BlogPost.update({_id: blogPostId, 'comments._id': commentId}, {$inc:{'comments.$.rating':1}})
.then((blogPost) => res.status(200).json({
'status': 'Comment rating is increased.'
}))
Example 2: inc a value mongoose
Models.post.Post.findOneAndUpdate({ _id: res._id }, { $inc: { views: 1 } }, {new: true },function(err, response) { if (err) { callback(err);} else { callback(response);}