Category: Database, Data

Today we’re going to see how MongoDB handles locks and how we can achieve Document-level locking.

This basically means we’re somewhat sure that nobody else is going to update our data while we’re working on it.

Using the FindOneAndUpdateAsync API, we can fetch the document and in the same operation, we can set both LockId and LockTime.

When we’re done with the document, we can release it by simply setting to null both LockId and LockTime.

Related Articles