@@ -9,28 +9,24 @@ data class Restaurant(val name: String, val cuisine: String)
9
9
10
10
fun main () {
11
11
// start-transaction
12
- // Creates a new MongoClient with a connection string
12
+ // Creates a new MongoClient to manage your connection
13
13
val client = MongoClients .create(" <connection string>" )
14
14
15
15
// Gets the database and collection
16
16
val database = client.getDatabase(" sample_restaurants" )
17
17
val collection = database.getCollection<Restaurant >(" restaurants" )
18
18
19
- // Defines options and inserts restaurants into the collection
19
+ // Inserts restaurants into the collection
20
20
fun insertRestaurantsInTransaction (session : ClientSession ) {
21
- // Sets options for the collection operation within the transaction
22
- val restaurantsCollectionWithOptions = collection
23
- .withWriteConcern(WriteConcern (" majority" ))
24
- .withReadConcern(ReadConcern .LOCAL )
25
21
26
22
// Inserts restaurants within the transaction
27
- restaurantsCollectionWithOptions .insertOne(
23
+ collection .insertOne(
28
24
session,
29
- Restaurant (" name " , " Kotlin Sync Pizza" ).append( " cuisine " , " Pizza" )
25
+ Restaurant (" Kotlin Sync Pizza" , " Pizza" )
30
26
)
31
- restaurantsCollectionWithOptions .insertOne(
27
+ collection .insertOne(
32
28
session,
33
- Restaurant (" name " , " Kotlin Sync Burger" ).append( " cuisine " , " Burger" )
29
+ Restaurant (" Kotlin Sync Burger" , " Burger" )
34
30
)
35
31
}
36
32
0 commit comments