what is a best approach to avoid Race Condition when same document is getting updated by multiple spring boot application

what is best approach to avoid race condition if same field of same document needs to be updated by multiple instance of spring boot application.

for updating field do i need to use spring repository or mongotemplate query based or any other best approach is there for this kind of scenario.