Skip to content

Commit fd6c16d

Browse files
committed
update references
1 parent f4055a8 commit fd6c16d

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

source/fundamentals/transactions.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Transactions
55
============
66

7-
.. default-domain:: mongodb
8-
97
.. contents:: On this page
108
:local:
119
:backlinks: none
@@ -40,23 +38,24 @@ guarantees that the data involved in your transaction operations remains
4038
consistent, even if the operations encounter unexpected errors.
4139

4240
When using the {+driver-short+}, you can create a new session from a
43-
``Client`` instance as a ``ClientSession``. We recommend that you reuse
41+
``MongoClient`` instance as a ``ClientSession`` type. We recommend that you reuse
4442
your client for multiple sessions and transactions instead of
4543
instantiating a new client each time.
4644

4745
.. warning::
4846

49-
Use a ``Session`` only with the ``Client`` (or associated
50-
``Database`` or ``Collection``) that created it. Using a
51-
``Session`` with a different ``Client`` results in operation
47+
Use a ``ClientSession`` only with the ``MongoClient`` (or associated
48+
``MongoDatabase`` or ``MongoCollection``) that created it. Using a
49+
``ClientSession`` with a different ``MongoClient`` results in operation
5250
errors.
5351

5452
Methods
5553
-------
5654

57-
After you start a session by using the ``startSession()`` method, you can modify
58-
the session state by using the method set provided by the ``Session`` interface.
59-
The following table describes these methods:
55+
Create a ``ClientSession`` by using the ``startSession()`` method on your
56+
``MongoClient``instance. You can then modify the session state by using the
57+
methods provided by the ``ClientSession``. The following table details the
58+
methods you can use to manage your transaction:
6059

6160
.. list-table::
6261
:widths: 25 75
@@ -108,7 +107,8 @@ and commit a multi-document insert operation through the following steps:
108107

109108
.. literalinclude:: /includes/fundamentals/code-snippets/Transaction.java
110109
:language: java
111-
:start-after: end imports
110+
:start-after: start transaction
111+
:end-after: end transaction
112112

113113
If you require more control over your transactions, you can use the ``startTransaction()``
114114
method. This method allows you to explicitly commit or abort the transaction and manually

source/includes/fundamentals/code-snippets/Transaction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void main(String[] args) {
1616
try (MongoClient mongoClient = MongoClients.create(connectionString)) {
1717
MongoDatabase database = mongoClient.getDatabase("yourDatabaseName");
1818
MongoCollection<Document> collection = database.getCollection("yourCollectionName");
19-
19+
// start transaction
2020
// Set transaction options
2121
TransactionOptions txnOptions = TransactionOptions.builder()
2222
.writeConcern(WriteConcern.MAJORITY)
@@ -37,5 +37,6 @@ public static void main(String[] args) {
3737
} catch (Exception e) {
3838
e.printStackTrace();
3939
}
40+
// end transaction
4041
}
4142
}

0 commit comments

Comments
 (0)