@@ -15,18 +15,18 @@ Transactions
15
15
:class: twocols
16
16
17
17
.. meta::
18
- :description: For situations that require atomicity of reads and writes to multiple documents (in a single or multiple collections), MongoDB supports multi-document transactions.
18
+ :description: For situations that require atomicity of reads and writes to multiple documents (in a single or multiple collections), MongoDB supports multi-document transactions, also called distributed transactions .
19
19
:keywords: MongoDB, transactions, distributed transactions, MongoDB multi-document transactions, MongoDB multi-statement transactions, java transaction examples, python transaction examples, node transaction examples, php transaction examples, scala transaction examples, csharp transaction examples, perl transaction examples, ruby transaction examples
20
20
21
21
In MongoDB, an operation on a single document is atomic. Because you can
22
22
use embedded documents and arrays to capture relationships between data
23
23
in a single document structure instead of normalizing across multiple
24
24
documents and collections, this single-document atomicity obviates the
25
- need for multi-document transactions for many practical use cases.
25
+ need for distributed transactions for many practical use cases.
26
26
27
27
For situations that require atomicity of reads and writes to multiple
28
28
documents (in a single or multiple collections), MongoDB supports
29
- multi-document transactions. With distributed transactions,
29
+ distributed transactions. With distributed transactions,
30
30
transactions can be used across multiple operations, collections,
31
31
databases, documents, and shards.
32
32
@@ -334,32 +334,10 @@ This example highlights the key components of the transactions API.
334
334
Transactions and Atomicity
335
335
--------------------------
336
336
337
- .. note :: Distributed Transactions and Multi-Document Transactions
337
+ .. include :: /includes/transactions/distributed-transaction-repl-shard-support.rst
338
338
339
- Starting in MongoDB 4.2, the two terms are synonymous. Distributed
340
- transactions refer to multi-document transactions on sharded
341
- clusters and replica sets. Multi-document transactions (whether on
342
- sharded clusters or replica sets) are also known as distributed
343
- transactions starting in MongoDB 4.2.
344
-
345
- For situations that require atomicity of reads and writes to multiple
346
- documents (in a single or multiple collections), MongoDB supports
347
- multi-document transactions:
348
-
349
- - **In version 4.0**, MongoDB supports multi-document transactions on
350
- replica sets.
351
-
352
- - **In version 4.2**, MongoDB introduces distributed transactions,
353
- which adds support for multi-document transactions on sharded
354
- clusters and incorporates the existing support for
355
- multi-document transactions on replica sets.
356
-
357
- To use transactions on MongoDB 4.2 deployments (replica sets and
358
- sharded clusters), clients :red:`must` use MongoDB drivers updated for
359
- MongoDB 4.2.
360
-
361
- Multi-document transactions are atomic (i.e. provide an
362
- "all-or-nothing" proposition):
339
+ Distributed transactions are atomic. They provide an "all-or-nothing"
340
+ proposition:
363
341
364
342
- When a transaction commits, all data changes made in the transaction
365
343
are saved and visible outside the transaction. That is, a transaction
@@ -385,7 +363,7 @@ Transactions and Operations
385
363
---------------------------
386
364
387
365
Distributed transactions can be used across multiple operations,
388
- collections, databases, documents, and, starting in MongoDB 4.2, shards.
366
+ collections, databases, documents, and shards.
389
367
390
368
For transactions:
391
369
@@ -405,19 +383,15 @@ For a list of operations not supported in transactions, see
405
383
Create Collections and Indexes In a Transaction
406
384
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
407
385
408
- Starting in MongoDB 4.4, you can perform the following operations inside
409
- of a :doc:`multi-document transaction </core/ transactions>` as long as
410
- the transaction is not a cross-shard write transaction:
386
+ You can perform the following operations inside of a :ref:`distributed
387
+ transaction <transactions>` as long as the transaction is not a
388
+ cross-shard write transaction:
411
389
412
390
- Create collections.
413
391
414
392
- Create indexes on new empty collections created earlier in the same
415
393
transaction.
416
394
417
- In MongoDB 4.2 and earlier, operations that affect the database catalog,
418
- such as creating or dropping a collection or an index, are
419
- :red:`disallowed` in transactions.
420
-
421
395
When creating a collection inside a transaction:
422
396
423
397
- You can :ref:`implicitly create a collection
@@ -514,8 +488,7 @@ Restricted Operations
514
488
Transactions and Sessions
515
489
-------------------------
516
490
517
- - Transactions are associated with a session; i.e. you start a
518
- transaction for a session.
491
+ - Transactions are associated with a session
519
492
520
493
- At any given time, you can have at most one open transaction for a
521
494
session.
@@ -593,20 +566,17 @@ Transactions support the following read concern levels:
593
566
``"majority"``
594
567
``````````````
595
568
596
- - Read concern :readconcern:`"majority"` returns data that has been
597
- acknowledged by a majority of the replica set members (i.e. data
598
- cannot be rolled back) **if** the transaction commits with
599
- :ref:`write concern "majority" <transactions-write-concern>`.
600
-
601
- - If the transaction does not use :ref:`write concern "majority"
602
- <transactions-write-concern>` for the commit, the
603
- :readconcern:`"majority"` read concern provides **no** guarantees that
604
- read operations read majority-committed data.
569
+ - If the transaction commits with :ref:`write concern "majority"
570
+ <transactions-write-concern>`, read concern :readconcern:`"majority"`
571
+ returns data that has been acknowledged by a majority of the replica
572
+ set members and can't be rolled back. Otherwise, read concern
573
+ :readconcern:`"majority"` provides no guarantees that read operations
574
+ read majority-committed data.
605
575
606
- - For transactions on sharded cluster, :readconcern:`"majority"` read
607
- concern cannot guarantee that the data is from the same snapshot
608
- view across the shards. If snapshot isolation is required, use
609
- :ref:`transactions-read-concern-snapshot` read concern .
576
+ - For transactions on sharded cluster, read concern
577
+ :readconcern:`"majority"` can't guarantee that the data is from the
578
+ same snapshot view across the shards. If snapshot isolation is
579
+ required, use read concern :ref:`transactions-read-concern-snapshot`.
610
580
611
581
.. _transactions-read-concern-snapshot:
612
582
@@ -660,7 +630,7 @@ You can set the transaction-level :doc:`write concern
660
630
<replica-set-arbiter-configuration>`. See
661
631
:ref:`wc-default-behavior`.
662
632
663
- - :writeconcern:`w: 1 <\<number\>>` in MongoDB 4.4 and earlier.
633
+ - :writeconcern:`w: 1 <\<number\>>`
664
634
665
635
.. seealso::
666
636
@@ -696,7 +666,7 @@ values, including:
696
666
697
667
- Write concern :writeconcern:`w: "majority" <"majority">` returns
698
668
acknowledgement after the commit has been applied to a majority
699
- (M) of voting members; i.e. the commit has been applied to the
669
+ (M) of voting members, meaning the commit has been applied to the
700
670
primary and (M-1) voting secondaries.
701
671
702
672
- When you commit with :writeconcern:`w: "majority" <"majority">`
@@ -793,7 +763,7 @@ MongoDB provides various transactions metrics:
793
763
794
764
* - :binary:`~bin.mongod` and :binary:`~bin.mongos` log messages
795
765
796
- - Includes information on slow transactions (i.e. transactions
766
+ - Includes information on slow transactions, which are transactions
797
767
that exceed the :setting:`operationProfiling.slowOpThresholdMs`
798
768
threshold) under the :data:`TXN` log component.
799
769
0 commit comments