@@ -41,3 +41,45 @@ effect. Rather, if you need to close the connection pool, use
4141.. versionadded :: 5.2.0b0
4242
4343 Support for connection pooling and ``connection.close_pool() `` were added.
44+
45+ .. _transactions :
46+
47+ Transactions
48+ ============
49+
50+ .. versionadded :: 5.2.0b2
51+
52+ Support for :doc: `Django's transactions APIs <django:topics/db/transactions >`
53+ is enabled if the MongoDB configuration supports them: MongoDB must be
54+ configured as a :doc: `replica set <manual:replication >` or :doc: `sharded
55+ cluster <manual:sharding>`, and the store engine must be :doc: `WiredTiger
56+ <manual:core/wiredtiger>`.
57+
58+ If transactions aren't supported, query execution uses Django and MongoDB's
59+ default behavior of autocommit mode. Each query is immediately committed to the
60+ database. Django's transaction management APIs, such as
61+ :func: `~django.db.transaction.atomic `, function as no-ops.
62+
63+ .. _transactions-limitations :
64+
65+ Limitations
66+ -----------
67+
68+ MongoDB's transaction limitations that are applicable to Django are:
69+
70+ - :meth: `QuerySet.union() <django.db.models.query.QuerySet.union> ` is not
71+ supported inside a transaction.
72+ - If a transaction raises an exception, the transaction is no longer usable.
73+ For example, if the update stage of :meth: `QuerySet.update_or_create()
74+ <django.db.models.query.QuerySet.update_or_create> ` fails with
75+ :class: `~django.db.IntegrityError ` due to a unique constraint violation, the
76+ create stage won't be able to proceed.
77+ :class: `pymongo.errors.OperationFailure ` is raised, wrapped by
78+ :class: `django.db.DatabaseError `.
79+ - Savepoints (i.e. nested :func: `~django.db.transaction.atomic ` blocks) aren't
80+ supported. The outermost :func: `~django.db.transaction.atomic ` will start
81+ a transaction while any subsequent :func: `~django.db.transaction.atomic `
82+ blocks will have no effect.
83+ - Migration operations aren't :ref: `wrapped in a transaction
84+ <topics/migrations:transactions>` because of MongoDB restrictions such as
85+ adding indexes to existing collections while in a transaction.
0 commit comments