MongoDB Documentation, Release 3.0.4 { application: "App1", state: "pending", lastModified: { $lt: dateThreshold } } ) Using Two-Phase Commits in Production Applications The example transaction above is intentionally simple. For example, it assumes that it is always possible to roll back operations to an account and that account balances can hold negative values. Production implementations would likely be more complex. Typically, accounts need information about current bal- ance, pending credits, and pending debits. For all transactions, ensure that you use the appropriate level of write concern (page 78) for your deployment. The Update if Current pattern is an approach to concurrency control (page 82) when multiple applications have access to the data. The pattern queries for the document to update. Then, for each field to modify, the pattern includes the field and its value in the returned document in the query predicate for the update operation. This way, the update only modifies the document fields if the fields have not changed since the query. Consider the following example in the mongo shell. The example updates the quantity and the reordered fields of a document only if the fields have not changed since the query. Changed in version 2.6: The db.collection.update() method now returns a WriteResult() object that contains the status of the operation. Previous versions required an extra db.getLastErrorObj() method call. 3.3.10 Update Document if Current Overview Pattern Example var myDocument = db.products.findOne( { sku: "abc123" } ); if ( myDocument ) { var oldQuantity = myDocument.quantity; var oldReordered = myDocument.reordered; var results = db.products.update( { _id: myDocument._id, quantity: oldQuantity, reordered: oldReordered }, { $inc: { quantity: 50 }, $set: { reordered: true } } Chapter 3. MongoDB CRUD Operations 122