MongoDB Documentation, Release 3.0.4 Step 6: Update transaction state to done. Complete the transaction by setting the state of the transaction to done and updating the lastModified field: Upon successful update, the method returns a WriteResult() object with nMatched and nModified set to 1 . The most important part of the transaction procedure is not the prototypical example above, but rather the possibility for recovering from the various failure scenarios when transactions do not complete successfully. This section presents an overview of possible failures and provides steps to recover from these kinds of events. The two-phase commit pattern allows applications running the sequence to resume the transaction and arrive at a consistent state. Run the recovery operations at application startup, and possibly at regular intervals, to catch any unfinished transactions. The time required to reach a consistent state depends on how long the application needs to recover each transaction. The following recovery procedures uses the lastModified date as an indicator of whether the pending transaction requires recovery; specifically, if the pending or applied transaction has not been updated in the last 30 minutes, the procedures determine that these transactions require recovery. You can use different conditions to make this determination. Transactions in Pending State To recover from failures that occur after step “Update transaction state to pending. (page ?? )” but before “Update transaction state to applied. (page ?? )” step, retrieve from the transactions collection a pending transaction for recovery: Transactions in Applied State To recover from failures that occur after step “Update transaction state to applied. (page ?? )” but before “Update transaction state to done. (page ?? )” step, retrieve from the transactions collection an applied transaction for recovery: And resume from “Update both accounts’ list of pending transactions. (page ?? )“ 119 3.3. MongoDB CRUD Tutorials Recovering from Failure Scenarios Recovery Operations db.transactions.update( { _id: t._id, state: "applied" }, { $set: { state: "done" }, $currentDate: { lastModified: true } } ) var dateThreshold = new Date(); dateThreshold.setMinutes(dateThreshold.getMinutes() - 30); var t = db.transactions.findOne( { state: "pending", lastModified: { $lt: dateThreshold } } ); And resume from step “Apply the transaction to both accounts. (page ?? )“ var dateThreshold = new Date(); dateThreshold.setMinutes(dateThreshold.getMinutes() - 30); var t = db.transactions.findOne( { state: "applied", lastModified: { $lt: dateThreshold } } );