@@ -24,18 +24,18 @@ Transactions
24
24
:class: twocols
25
25
26
26
.. meta::
27
- :description: For situations that require atomicity of reads and writes to multiple documents (in a single or multiple collections), MongoDB supports multi-document transactions.
27
+ :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 .
28
28
: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
29
29
30
30
In MongoDB, an operation on a single document is atomic. Because you can
31
31
use embedded documents and arrays to capture relationships between data
32
32
in a single document structure instead of normalizing across multiple
33
33
documents and collections, this single-document atomicity obviates the
34
- need for multi-document transactions for many practical use cases.
34
+ need for distributed transactions for many practical use cases.
35
35
36
36
For situations that require atomicity of reads and writes to multiple
37
37
documents (in a single or multiple collections), MongoDB supports
38
- multi-document transactions. With distributed transactions,
38
+ distributed transactions. With distributed transactions,
39
39
transactions can be used across multiple operations, collections,
40
40
databases, documents, and shards.
41
41
@@ -288,32 +288,10 @@ upper-right to set the language of the following example.
288
288
Transactions and Atomicity
289
289
--------------------------
290
290
291
- .. note :: Distributed Transactions and Multi-Document Transactions
291
+ .. include :: /includes/transactions/distributed-transaction-repl-shard-support.rst
292
292
293
- Starting in MongoDB 4.2, the two terms are synonymous. Distributed
294
- transactions refer to multi-document transactions on sharded
295
- clusters and replica sets. Multi-document transactions (whether on
296
- sharded clusters or replica sets) are also known as distributed
297
- transactions starting in MongoDB 4.2.
298
-
299
- For situations that require atomicity of reads and writes to multiple
300
- documents (in a single or multiple collections), MongoDB supports
301
- multi-document transactions:
302
-
303
- - **In version 4.0**, MongoDB supports multi-document transactions on
304
- replica sets.
305
-
306
- - **In version 4.2**, MongoDB introduces distributed transactions,
307
- which adds support for multi-document transactions on sharded
308
- clusters and incorporates the existing support for
309
- multi-document transactions on replica sets.
310
-
311
- To use transactions on MongoDB 4.2 deployments (replica sets and
312
- sharded clusters), clients :red:`must` use MongoDB drivers updated for
313
- MongoDB 4.2.
314
-
315
- Multi-document transactions are atomic (i.e. provide an
316
- "all-or-nothing" proposition):
293
+ Distributed transactions are atomic. They provide an "all-or-nothing"
294
+ proposition:
317
295
318
296
- When a transaction commits, all data changes made in the transaction
319
297
are saved and visible outside the transaction. That is, a transaction
@@ -339,7 +317,7 @@ Transactions and Operations
339
317
---------------------------
340
318
341
319
Distributed transactions can be used across multiple operations,
342
- collections, databases, documents, and, starting in MongoDB 4.2, shards.
320
+ collections, databases, documents, and shards.
343
321
344
322
For transactions:
345
323
@@ -359,19 +337,15 @@ For a list of operations not supported in transactions, see
359
337
Create Collections and Indexes In a Transaction
360
338
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361
339
362
- Starting in MongoDB 4.4, you can perform the following operations inside
363
- of a :ref:`multi-document transaction <transactions>` as long as
364
- the transaction is not a cross-shard write transaction:
340
+ You can perform the following operations inside of a :ref:`distributed
341
+ transaction <transactions>` as long as the transaction is not a
342
+ cross-shard write transaction:
365
343
366
344
- Create collections.
367
345
368
346
- Create indexes on new empty collections created earlier in the same
369
347
transaction.
370
348
371
- In MongoDB 4.2 and earlier, operations that affect the database catalog,
372
- such as creating or dropping a collection or an index, are
373
- :red:`disallowed` in transactions.
374
-
375
349
When creating a collection inside a transaction:
376
350
377
351
- You can :ref:`implicitly create a collection
@@ -470,8 +444,7 @@ Restricted Operations
470
444
Transactions and Sessions
471
445
-------------------------
472
446
473
- - Transactions are associated with a session; i.e. you start a
474
- transaction for a session.
447
+ - Transactions are associated with a session
475
448
476
449
- At any given time, you can have at most one open transaction for a
477
450
session.
@@ -549,20 +522,17 @@ Transactions support the following read concern levels:
549
522
``"majority"``
550
523
``````````````
551
524
552
- - Read concern :readconcern:`"majority"` returns data that has been
553
- acknowledged by a majority of the replica set members (i.e. data
554
- cannot be rolled back) **if** the transaction commits with
555
- :ref:`write concern "majority" <transactions-write-concern>`.
556
-
557
- - If the transaction does not use :ref:`write concern "majority"
558
- <transactions-write-concern>` for the commit, the
559
- :readconcern:`"majority"` read concern provides **no** guarantees that
560
- read operations read majority-committed data.
525
+ - If the transaction commits with :ref:`write concern "majority"
526
+ <transactions-write-concern>`, read concern :readconcern:`"majority"`
527
+ returns data that has been acknowledged by a majority of the replica
528
+ set members and can't be rolled back. Otherwise, read concern
529
+ :readconcern:`"majority"` provides no guarantees that read operations
530
+ read majority-committed data.
561
531
562
- - For transactions on sharded cluster, :readconcern:`"majority"` read
563
- concern cannot guarantee that the data is from the same snapshot
564
- view across the shards. If snapshot isolation is required, use
565
- :ref:`transactions-read-concern-snapshot` read concern .
532
+ - For transactions on sharded cluster, read concern
533
+ :readconcern:`"majority"` can't guarantee that the data is from the
534
+ same snapshot view across the shards. If snapshot isolation is
535
+ required, use read concern :ref:`transactions-read-concern-snapshot`.
566
536
567
537
.. _transactions-read-concern-snapshot:
568
538
@@ -616,7 +586,7 @@ You can set the transaction-level :doc:`write concern
616
586
<replica-set-arbiter-configuration>`. See
617
587
:ref:`wc-default-behavior`.
618
588
619
- - :writeconcern:`w: 1 <\<number\>>` in MongoDB 4.4 and earlier.
589
+ - :writeconcern:`w: 1 <\<number\>>`
620
590
621
591
.. seealso::
622
592
@@ -652,7 +622,7 @@ values, including:
652
622
653
623
- Write concern :writeconcern:`w: "majority" <"majority">` returns
654
624
acknowledgement after the commit has been applied to a majority
655
- (M) of voting members; i.e. the commit has been applied to the
625
+ (M) of voting members, meaning the commit has been applied to the
656
626
primary and (M-1) voting secondaries.
657
627
658
628
- When you commit with :writeconcern:`w: "majority" <"majority">`
@@ -749,7 +719,7 @@ MongoDB provides various transactions metrics:
749
719
750
720
* - :binary:`~bin.mongod` and :binary:`~bin.mongos` log messages
751
721
752
- - Includes information on slow transactions (i.e. transactions
722
+ - Includes information on slow transactions, which are transactions
753
723
that exceed the :setting:`operationProfiling.slowOpThresholdMs`
754
724
threshold) under the :data:`TXN` log component.
755
725
0 commit comments