Note: Features under development in this section are not part of the standard djongo package. Visit the support page for more information.
Transaction and Commit
Djongo integrates with MongoDB Transactions API to support multi document atomic transactions. Atomic transactions are enabled in Django using the usual
transaction.atomic() decorator or context manager. MongoDB transactions significantly speed up Django test execution and validation.
from djongo import transaction def viewfunc(request): stuff() with transaction.atomic(): # This code executes inside a transaction. more_stuff()
This produces the following pymongo commands:
session = cli.start_session() transaction = session.start_transaction() # more_stuff transaction.commit_transaction() # or transaction.abort_transaction() session.end_session()