Skip to content

Commit 795e1fd

Browse files
committed
update code examples
1 parent 8bb6af1 commit 795e1fd

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

source/examples/generated/TransactionsTest.snippet.transaction.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Set up the MongoDB client and get the collection
22
suspend fun performTransaction(client: MongoClient) {
33
client.startSession().use { session ->
4-
session.startTransaction() // Start the transaction
4+
// Start the transaction
5+
session.startTransaction()
56
try {
67
val database = client.getDatabase("bank")
78

@@ -18,6 +19,7 @@ suspend fun performTransaction(client: MongoClient) {
1819
CheckingAccount::accountId eq "9876",
1920
inc(CheckingAccount::amount, 100)
2021
)
22+
2123
// Commit the transaction
2224
session.commitTransaction()
2325
println("Transaction committed.")
@@ -28,12 +30,3 @@ suspend fun performTransaction(client: MongoClient) {
2830
}
2931
}
3032
}
31-
32-
data class SavingsAccount(val accountId: String, val amount: Int)
33-
data class CheckingAccount(val accountId: String, val amount: Int)
34-
35-
fun main() = runBlocking {
36-
val uri = "<connection string uri>"
37-
val client = MongoClient.create(uri)
38-
performTransaction(client)
39-
}

source/fundamentals/transactions.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ and commit a changes to existing documents:
9696
#. Update the specified documents, then use the ``commitTransaction()`` method if all
9797
operations succeed, or ``abortTransaction()`` if any operations fail.
9898

99+
This example uses the following {+language+} data classes to model its documents:
100+
101+
.. code-block:: kotlin
102+
103+
data class SavingsAccount(val accountId: String, val amount: Int)
104+
data class CheckingAccount(val accountId: String, val amount: Int)
105+
99106
.. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction.kt
100107
:language: kotlin
101108
:copyable:

0 commit comments

Comments
 (0)