In this article, I’m going to sketch a pattern for implementing pessimistic locking with MongoDB. MongoDB is a document-orientated NoSQL datastore that does not support locking itself.
In some business processes it may be required that you have an exclusive access to a single document. That’s when you need something like pessimistic locking.
Requirements
The implementation should offer the following features:
Locking does not change the locked document itself
Locks can be removed manually or by a timeout
For the rest of this article, let’s assume we want to lock documents in a collection called workitem.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/301743/viewspace-747237/
,如需转载,请注明出处,否则将追究法律责任。