'make repository mutually exclusive in springboot

Is there a way to make a repository mutually exclusive i.e two concurrent values not update the same document in Springboot. My code structure is.

//func(version,cid)
//make a api call for cid
//fetch the document with that version
//update the document with result against the cid

all API calls are concurrently editing the same document

ps: I can share code if needed. database image



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source