I'm creating a match-making system via the MongoDB drivers for Golang.
I have a collection called sessions
.
When a user tries to join a match, a find()
query will return active sessions. Then the user will be placed in one of those active sessions.
But what if, at the same time, one of those sessions was closed via updateOne()
? Then the documents from find()
are no longer valid.
So I would like all queries in the collection to be blocked until updates are done.
I know I can implement my own mutex for this case. But I want to know if MongoDB has any API for this as well? If not, any examples to how I can approach this (whether it's with sync.Mutex
or sync.RWMutex
)?