DocumentLocking.bwp

This process demonstrates how to use the plug-in's QueryDocument Activity to lock documents in a transaction. Activities are added to the Local Transaction Group. Configuration is mentioned in the section MongoDB Transactions. Locking a document does not allow any concurrent transaction to modify/remove it until the lock is released. Nested Transaction is used by creating another Local Transaction Group that creates a second transaction.

The process is designed with the following activities:

The following table describes the activities in the process.

Activity Description
RemoveDocument Removes all the documents in the specified collection.
InsertDocument Inserts a document in the specified collection with the fields Name and Age.
QueryDocument Locks the first document that matches the input in QueryDocument as Lock Document checkbox is checked and QueryType FIND_ONE is selected.
UpdateDocument This activity is in a nested transaction. UpdateDocumentActivity throws a WriteConflict exception as the document that it is trying to update is locked by QueryDocumentActivity in the outer transaction. Lock can only be released when the outer transaction session is committed which cannot be done with out the inner transaction successfully committing leading to a deadlock here.