Skip to content

Commit f0b50af

Browse files
committed
update example references
1 parent d57a4cf commit f0b50af

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

source/includes/write/transaction.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,24 @@ data class Restaurant(val name: String, val cuisine: String)
99

1010
fun main() {
1111
// start-transaction
12-
// Creates a new MongoClient with a connection string
12+
// Creates a new MongoClient to manage your connection
1313
val client = MongoClients.create("<connection string>")
1414

1515
// Gets the database and collection
1616
val database = client.getDatabase("sample_restaurants")
1717
val collection = database.getCollection<Restaurant>("restaurants")
1818

19-
// Defines options and inserts restaurants into the collection
19+
// Inserts restaurants into the collection
2020
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)
2521

2622
// Inserts restaurants within the transaction
27-
restaurantsCollectionWithOptions.insertOne(
23+
collection.insertOne(
2824
session,
29-
Restaurant("name", "Kotlin Sync Pizza").append("cuisine", "Pizza")
25+
Restaurant("Kotlin Sync Pizza", "Pizza")
3026
)
31-
restaurantsCollectionWithOptions.insertOne(
27+
collection.insertOne(
3228
session,
33-
Restaurant("name", "Kotlin Sync Burger").append("cuisine", "Burger")
29+
Restaurant("Kotlin Sync Burger", "Burger")
3430
)
3531
}
3632

source/write/transactions.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ transaction, and insert documents into a collection in one transaction
117117
through the following steps:
118118

119119
1. Create a session from the client by using the ``startSession()`` method.
120-
#. Use the ``withTransaction()`` method to start a transaction.
121-
#. Insert multiple documents into the ``restaurants`` collection. The
122-
``withTransaction()`` method runs the insert operation and commits the
123-
transaction. If any operation results in errors, ``withTransaction()``
124-
cancels the transaction.
120+
#. Define the ``insertRestaurantsInTransaction`` method to insert multiple
121+
documents into the ``restaurants`` collection.
122+
#. Use the ``withTransaction()`` method to start a transaction. The ``withTransaction()``
123+
method runs the insert operation and commits the transaction. If any
124+
operation results in errors, ``withTransaction()`` cancels the transaction.
125125
#. Close the connection to the server by using the ``client.close()`` method.
126126

127127
.. literalinclude:: /includes/write/transaction.kt

0 commit comments

Comments
 (0)