You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
guarantees that the data involved in your transaction operations remains
38
+
consistent, even if the operations encounter unexpected errors.
39
+
40
+
When using the {+driver-short+}, you can create a new session from a
40
41
``Client`` instance as a ``Session`` type. We recommend that you reuse
41
42
your client for multiple sessions and transactions instead of
42
43
instantiating a new client each time.
@@ -45,7 +46,7 @@ instantiating a new client each time.
45
46
46
47
Use a ``Session`` only with the ``Client`` (or associated
47
48
``Database`` or ``Collection``) that created it. Using a
48
-
``Session`` with a different ``Client`` will result in operation
49
+
``Session`` with a different ``Client`` results in operation
49
50
errors.
50
51
51
52
.. warning::
@@ -56,8 +57,8 @@ instantiating a new client each time.
56
57
Methods
57
58
-------
58
59
59
-
After you start a session using the ``StartSession()`` method, you can modify
60
-
the session state using the method set provided by the ``Session`` interface. The
60
+
After you start a session by using the ``StartSession()`` method, you can modify
61
+
the session state by using the method set provided by the ``Session`` interface. The
61
62
following table describes these methods:
62
63
63
64
.. list-table::
@@ -70,26 +71,41 @@ following table describes these methods:
70
71
* - ``StartTransaction()``
71
72
- | Starts a new transaction, configured with the given options, on
72
73
this session. Returns an error if there is already
73
-
a transaction in progress for the session. For more
74
-
information, see the :manual:`manual entry </reference/method/Session.startTransaction/>`.
74
+
a transaction in progress for the session. To learn more about
75
+
this method, see the :manual:`startTransaction() page
76
+
</reference/method/Session.startTransaction/>` in the Server manual.
75
77
|
76
78
| **Parameter**: ``TransactionOptions``
77
79
| **Return Type**: ``error``
78
80
79
81
* - ``AbortTransaction()``
80
-
- | Aborts the active transaction for this session. Returns an
82
+
- | Ends the active transaction for this session. Returns an
81
83
error if there is no active transaction for the session or the
82
-
transaction has been committed or aborted. For more
83
-
information, see the :manual:`manual entry </reference/method/Session.abortTransaction/>`.
84
+
transaction has been committed or ended. To learn more about
85
+
this method, see the :manual:`abortTransaction() page
86
+
</reference/method/Session.abortTransaction/>` in the Server manual.
84
87
|
85
88
| **Parameter**: ``Context``
86
89
| **Return Type**: ``error``
87
90
88
91
* - ``CommitTransaction()``
89
92
- | Commits the active transaction for this session. Returns an
90
-
error if there is no active transaction for the session or the
91
-
transaction has been aborted. For more
92
-
information, see the :manual:`manual entry </reference/method/Session.commitTransaction/>`.
93
+
error if there is no active transaction for the session or if the
94
+
transaction was ended. To learn more about
95
+
this method, see the :manual:`commitTransaction() page
96
+
</reference/method/Session.commitTransaction/>` in the Server manual.
97
+
98
+
.. note:: Retrying a Transaction
99
+
100
+
The ``CommitTransaction()`` method is an idempotent function, which
101
+
means that you can attempt to commit a transaction multiple times
102
+
without changing data after the first successful commit.
103
+
104
+
A transaction can succeed but return an error with the
105
+
``UnknownTransactionCommitResult`` label. If you rerun the
106
+
``CommitTransaction()`` method after receiving this error,
107
+
your data is not changed by the repeat attempts.
108
+
93
109
|
94
110
| **Parameter**: ``Context``
95
111
| **Return Type**: ``error``
@@ -102,7 +118,7 @@ following table describes these methods:
102
118
| **Return Type**: ``interface{}``, ``error``
103
119
104
120
* - ``EndSession()``
105
-
- | Aborts any existing transactions and closes the session.
121
+
- | Ends any existing transactions and closes the session.
106
122
|
107
123
| **Parameter**: ``Context``
108
124
| **Return Type**: none
@@ -133,7 +149,7 @@ following steps:
133
149
:end-before: end-session
134
150
135
151
If you require more control over your transactions, you can find an example
136
-
showing how to manually create, commit, and abort transactions in the
152
+
showing how to manually create, commit, and end transactions in the
137
153
`full code example <https://raw.githubusercontent.com/mongodb/docs-golang/{+docs-branch+}/source/includes/fundamentals/code-snippets/transaction.go>`__.
0 commit comments