MongoDB Documentation, Release 3.0.4 Rollback Operations In some cases, you may need to “roll back” or undo a transaction; e.g., if the application needs to “cancel” the transaction or if one of the accounts does not exist or stops existing during the transaction. Transactions in Applied State After the “Update transaction state to applied. (page ?? )” step, you should not roll back the transaction. Instead, complete that transaction and create a new transaction (page 117) to reverse the transaction by switching the values in the source and the destination fields. Transactions in Pending State After the “Update transaction state to pending. (page ?? )” step, but before the “Update transaction state to applied. (page ?? )” step, you can rollback the transaction using the following procedure: Step 1: Update transaction state to canceling. Update the transaction state from pending to canceling . db.transactions.update( { _id: t._id, state: "pending" }, { $set: { state: "canceling" }, $currentDate: { lastModified: true } } ) Upon successful update, the method returns a WriteResult() object with nMatched and nModified set to 1 . Step 2: Undo the transaction on both accounts. To undo the transaction on both accounts, reverse the transaction t if the transaction has been applied. In the update condition, include the condition pendingTransactions: t._id in order to update the account only if the pending transaction has been applied. Update the destination account, subtracting from its balance the transaction value and removing the transaction _id from the pendingTransactions array. 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 . Update the source account, adding to its balance the transaction value and removing the transaction _id from the pendingTransactions array. Chapter 3. MongoDB CRUD Operations 120 db.accounts.update( { _id: t.destination, pendingTransactions: t._id }, { $inc: { balance: -t.value }, $pull: { pendingTransactions: t._id } } ) db.accounts.update( { _id: t.source, pendingTransactions: t._id }, { $inc: { balance: t.value}, $pull: { pendingTransactions: t._id } } )