File tree Expand file tree Collapse file tree 1 file changed +3
-6
lines changed
source/examples/generated Expand file tree Collapse file tree 1 file changed +3
-6
lines changed Original file line number Diff line number Diff line change 1
1
// 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 ->
4
4
session.startTransaction() // Start the transaction
5
5
try {
6
6
val database = client.getDatabase(" bank" )
7
7
8
8
val savingsColl = database.getCollection<SavingsAccount >(" savings_accounts" )
9
- savingsColl.findeOneAndUpdate (
9
+ savingsColl.findOneAndUpdate (
10
10
session,
11
11
SavingsAccount ::accountId eq " 9876" ,
12
12
inc(SavingsAccount ::amount, - 100 )
@@ -25,9 +25,6 @@ suspend fun performTransaction(client: CoroutineClient) {
25
25
println (" An error occurred during the transaction: ${error.message} " )
26
26
// Abort the transaction
27
27
session.abortTransaction()
28
- } finally {
29
- // End the session
30
- session.endSession()
31
28
}
32
29
}
33
30
}
You can’t perform that action at this time.
0 commit comments