How to handle multiple Nodejs requests reading, modifying and updating the same document at same time

Two processes read the same document and they perform some arithmetic operation and then update the document. So what happens is that one of the process will update first and then when second process updates the document, the changes made by the first process is lost.