Skip to content

Commit 90daadf

Browse files
committed
update code example
1 parent 800c43a commit 90daadf

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Set up the MongoDB client and get the collection
2-
suspend fun performTransaction(client: CoroutineClient) {
3-
client.startSession().use { session: ClientSession ->
2+
suspend fun performTransaction(client: MongoClient) {
3+
client.startSession().use { session ->
44
session.startTransaction() // Start the transaction
55
try {
66
val database = client.getDatabase("bank")
77

88
val savingsColl = database.getCollection<SavingsAccount>("savings_accounts")
9-
savingsColl.findeOneAndUpdate(
9+
savingsColl.findOneAndUpdate(
1010
session,
1111
SavingsAccount::accountId eq "9876",
1212
inc(SavingsAccount::amount, -100)
@@ -25,9 +25,6 @@ suspend fun performTransaction(client: CoroutineClient) {
2525
println("An error occurred during the transaction: ${error.message}")
2626
// Abort the transaction
2727
session.abortTransaction()
28-
} finally {
29-
// End the session
30-
session.endSession()
3128
}
3229
}
3330
}

0 commit comments

Comments
 (0)