@@ -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
@@ -279,32 +279,10 @@ upper-right to set the language of the following example.
279
279
Transactions and Atomicity
280
280
--------------------------
281
281
282
- .. note :: Distributed Transactions and Multi-Document Transactions
282
+ .. include :: /includes/transactions/distributed-transaction-repl-shard-support.rst
283
283
284
- Starting in MongoDB 4.2, the two terms are synonymous. Distributed
285
- transactions refer to multi-document transactions on sharded
286
- clusters and replica sets. Multi-document transactions (whether on
287
- sharded clusters or replica sets) are also known as distributed
288
- transactions starting in MongoDB 4.2.
289
-
290
- For situations that require atomicity of reads and writes to multiple
291
- documents (in a single or multiple collections), MongoDB supports
292
- multi-document transactions:
293
-
294
- - **In version 4.0**, MongoDB supports multi-document transactions on
295
- replica sets.
296
-
297
- - **In version 4.2**, MongoDB introduces distributed transactions,
298
- which adds support for multi-document transactions on sharded
299
- clusters and incorporates the existing support for
300
- multi-document transactions on replica sets.
301
-
302
- To use transactions on MongoDB 4.2 deployments (replica sets and
303
- sharded clusters), clients :red:`must` use MongoDB drivers updated for
304
- MongoDB 4.2.
305
-
306
- Multi-document transactions are atomic (i.e. provide an
307
- "all-or-nothing" proposition):
284
+ Distributed transactions are atomic. They provide an "all-or-nothing"
285
+ proposition:
308
286
309
287
- When a transaction commits, all data changes made in the transaction
310
288
are saved and visible outside the transaction. That is, a transaction
@@ -330,7 +308,7 @@ Transactions and Operations
330
308
---------------------------
331
309
332
310
Distributed transactions can be used across multiple operations,
333
- collections, databases, documents, and, starting in MongoDB 4.2, shards.
311
+ collections, databases, documents, and shards.
334
312
335
313
For transactions:
336
314
@@ -350,19 +328,15 @@ For a list of operations not supported in transactions, see
350
328
Create Collections and Indexes In a Transaction
351
329
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352
330
353
- Starting in MongoDB 4.4, you can perform the following operations inside
354
- of a :ref:`multi-document transaction <transactions>` as long as
355
- the transaction is not a cross-shard write transaction:
331
+ You can perform the following operations inside of a :ref:`distributed
332
+ transaction <transactions>` as long as the transaction is not a
333
+ cross-shard write transaction:
356
334
357
335
- Create collections.
358
336
359
337
- Create indexes on new empty collections created earlier in the same
360
338
transaction.
361
339
362
- In MongoDB 4.2 and earlier, operations that affect the database catalog,
363
- such as creating or dropping a collection or an index, are
364
- :red:`disallowed` in transactions.
365
-
366
340
When creating a collection inside a transaction:
367
341
368
342
- You can :ref:`implicitly create a collection
@@ -461,8 +435,7 @@ Restricted Operations
461
435
Transactions and Sessions
462
436
-------------------------
463
437
464
- - Transactions are associated with a session; i.e. you start a
465
- transaction for a session.
438
+ - Transactions are associated with a session
466
439
467
440
- At any given time, you can have at most one open transaction for a
468
441
session.
@@ -540,20 +513,17 @@ Transactions support the following read concern levels:
540
513
``"majority"``
541
514
``````````````
542
515
543
- - Read concern :readconcern:`"majority"` returns data that has been
544
- acknowledged by a majority of the replica set members (i.e. data
545
- cannot be rolled back) **if** the transaction commits with
546
- :ref:`write concern "majority" <transactions-write-concern>`.
547
-
548
- - If the transaction does not use :ref:`write concern "majority"
549
- <transactions-write-concern>` for the commit, the
550
- :readconcern:`"majority"` read concern provides **no** guarantees that
551
- read operations read majority-committed data.
516
+ - If the transaction commits with :ref:`write concern "majority"
517
+ <transactions-write-concern>`, read concern :readconcern:`"majority"`
518
+ returns data that has been acknowledged by a majority of the replica
519
+ set members and can't be rolled back. Otherwise, read concern
520
+ :readconcern:`"majority"` provides no guarantees that read operations
521
+ read majority-committed data.
552
522
553
- - For transactions on sharded cluster, :readconcern:`"majority"` read
554
- concern cannot guarantee that the data is from the same snapshot
555
- view across the shards. If snapshot isolation is required, use
556
- :ref:`transactions-read-concern-snapshot` read concern .
523
+ - For transactions on sharded cluster, read concern
524
+ :readconcern:`"majority"` can't guarantee that the data is from the
525
+ same snapshot view across the shards. If snapshot isolation is
526
+ required, use read concern :ref:`transactions-read-concern-snapshot`.
557
527
558
528
.. _transactions-read-concern-snapshot:
559
529
@@ -607,7 +577,7 @@ You can set the transaction-level :doc:`write concern
607
577
<replica-set-arbiter-configuration>`. See
608
578
:ref:`wc-default-behavior`.
609
579
610
- - :writeconcern:`w: 1 <\<number\>>` in MongoDB 4.4 and earlier.
580
+ - :writeconcern:`w: 1 <\<number\>>`
611
581
612
582
.. seealso::
613
583
@@ -643,7 +613,7 @@ values, including:
643
613
644
614
- Write concern :writeconcern:`w: "majority" <"majority">` returns
645
615
acknowledgement after the commit has been applied to a majority
646
- (M) of voting members; i.e. the commit has been applied to the
616
+ (M) of voting members, meaning the commit has been applied to the
647
617
primary and (M-1) voting secondaries.
648
618
649
619
- When you commit with :writeconcern:`w: "majority" <"majority">`
@@ -740,7 +710,7 @@ MongoDB provides various transactions metrics:
740
710
741
711
* - :binary:`~bin.mongod` and :binary:`~bin.mongos` log messages
742
712
743
- - Includes information on slow transactions (i.e. transactions
713
+ - Includes information on slow transactions, which are transactions
744
714
that exceed the :setting:`operationProfiling.slowOpThresholdMs`
745
715
threshold) under the :data:`TXN` log component.
746
716
0 commit comments