For example< we have a next db structure:
- Users
- Items
- Games
Items belongs to Users (userId field in item) aka inventory. Users can create games. Users can join created games. Only two users allowed to join a game. When game is completed, all items from users inventories should be transferred to "winner" inventory.
I want to build a flow, by using NodeJs, to handle "joinGame", "winGame" cases. In a MySql database i used transactions to lock "game" record and perform all operations in a single transaction to ensure data consistency.
I have no idea how to make it in mongo in a correct way. Digging on internet, i found two solution:
- Write a worker, what cycles through a "game" records to finalize them.
- Use app-level (node executable) lock
- ?
Thank you in advance!