I have a code that updates the number of views on a particular post.
I did it like this:
models.Blog.findById(id).then(blog => {
models.Blog.update({views: blog.views+1}, {where: {id: blog.id}}).then(blog => {
//result
})
})
But if two user tries to update that model at once then there will be race condition.
My question is how to do the same thing and avoid race condition.