MongoDB Documentation, Release 3.0.4 3.3.9 Perform Two Phase Commits Synopsis db.inventory.find( { quantity: { $gte: 100, $lte: 300 }, type: "food" } ).hint({ type: 1, quantity: 1 }).explain("executionStats") { "queryPlanner" : { ... "winningPlan" : { "stage" : "FETCH", "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "type" : 1, "quantity" : 1 }, ... } }, "rejectedPlans" : [ ] }, "executionStats" : { "executionSuccess" : true , "nReturned" : 2, "executionTimeMillis" : 0, "totalKeysExamined" : 2, "totalDocsExamined" : 2, "executionStages" : { ... } }, ... } The explain() method returns the following output: MongoDB scanned 2 index keys ( executionStats.totalKeysExamined ) to return 2 matching documents ( executionStats.nReturned ). For this example query, the compound index { type: 1, quantity: 1 } is more efficient than the com- pound index { quantity: 1, type: 1 } . Query Optimization (page 65), Query Plans (page 68), Optimize Query Performance (page 216), Indexing Strategies (page 546) See also: This document provides a pattern for doing multi-document updates or “multi-document transactions” using a two- phase commit approach for writing data to multiple documents. Additionally, you can extend this process to provide a rollback-like (page 120) functionality. 115 3.3. MongoDB CRUD Tutorials