MongoDB Documentation, Release 3.0.4 Upon successful update, the method returns a WriteResult() object with nMatched and nModified set to 1 . If the pending transaction has not been previously applied to this account, no document will match the update condition and nMatched and nModified will be 0 . Step 3: Update transaction state to canceled. To finish the rollback, update the transaction state from canceling to cancelled . db.transactions.update( { _id: t._id, state: "canceling" }, { $set: { state: "cancelled" }, $currentDate: { lastModified: true } } ) Upon successful update, the method returns a WriteResult() object with nMatched and nModified set to 1 . Transactions exist, in part, so that multiple applications can create and run operations concurrently without causing data inconsistency or conflicts. In our procedure, to update or retrieve the transaction document, the update conditions include a condition on the state field to prevent reapplication of the transaction by multiple applications. For example, applications App1 and App2 both grab the same transaction, which is in the initial state. App1 applies the whole transaction before App2 starts. When App2 attempts to perform the “Update transaction state to pending. (page ?? )” step, the update condition, which includes the state: "initial" criterion, will not match any document, and the nMatched and nModified will be 0 . This should signal to App2 to go back to the first step to restart the procedure with a different transaction. When multiple applications are running, it is crucial that only one application can handle a given transaction at any point in time. As such, in addition including the expected state of the transaction in the update condition, you can also create a marker in the transaction document itself to identify the application that is handling the transaction. Use findAndModify() method to modify the transaction and get it back in one step: Amend the transaction operations to ensure that only applications that match the identifier in the application field apply the transaction. If the application App1 fails during transaction execution, you can use the recovery procedures (page 119), but appli- cations should ensure that they “own” the transaction before applying the transaction. For example to find and resume the pending job, use a query that resembles the following: 121 3.3. MongoDB CRUD Tutorials t = db.transactions.findAndModify( { query: { state: "initial", application: { $exists: false } }, update: { $set: { state: "pending", application: "App1" }, $currentDate: { lastModified: true } }, new : true } ) var dateThreshold = new Date(); dateThreshold.setMinutes(dateThreshold.getMinutes() - 30); db.transactions.find( Multiple Applications