From af1fdaa9b5a8de9b0c82560e09cccee8a2266122 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 12:20:59 -0700 Subject: [PATCH 01/20] add transactions page --- .../TransactionsTest.snippet.transaction.kt | 40 ++++++ source/fundamentals.txt | 1 + source/fundamentals/transactions.txt | 130 ++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 source/examples/generated/TransactionsTest.snippet.transaction.kt create mode 100644 source/fundamentals/transactions.txt diff --git a/source/examples/generated/TransactionsTest.snippet.transaction.kt b/source/examples/generated/TransactionsTest.snippet.transaction.kt new file mode 100644 index 00000000..b71360de --- /dev/null +++ b/source/examples/generated/TransactionsTest.snippet.transaction.kt @@ -0,0 +1,40 @@ +// Set up the MongoDB client and get the collection +suspend fun performTransaction(client: CoroutineClient) { + client.startSession().use { session: ClientSession -> + session.startTransaction() // Start the transaction + try { + val database = client.getDatabase("bank") + + val savingsColl = database.getCollection("savings_accounts") + savingsColl.findeOneAndUpdate( + session, + SavingsAccount::accountId eq "9876", + inc(SavingsAccount::amount, -100) + ) + + val checkingColl = database.getCollection("checking_accounts") + checkingColl.findOneAndUpdate( + session, + CheckingAccount::accountId eq "9876", + inc(CheckingAccount::amount, 100) + ) + // Commit the transaction + session.commitTransaction() + println("Transaction committed.") + } catch (error: Exception) { + println("An error occurred during the transaction: ${error.message}") + session.abortTransaction() // Abort the transaction + } finally { + session.endSession() // End the session + } + } +} + +data class SavingsAccount(val accountId: String, val amount: Int) +data class CheckingAccount(val accountId: String, val amount: Int) + +fun main() = runBlocking { + val uri = "" + val client = MongoClient.create(uri) + performTransaction(client) +} diff --git a/source/fundamentals.txt b/source/fundamentals.txt index 1ef41c30..a44f2708 100644 --- a/source/fundamentals.txt +++ b/source/fundamentals.txt @@ -19,6 +19,7 @@ Fundamentals /fundamentals/aggregation /fundamentals/aggregation-expression-operations /fundamentals/indexes + /fundamentals/transactions /fundamentals/collations /fundamentals/logging /fundamentals/monitoring diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt new file mode 100644 index 00000000..b53e72df --- /dev/null +++ b/source/fundamentals/transactions.txt @@ -0,0 +1,130 @@ +.. _kotlin-fundamentals-transactions: + +============ +Transactions +============ + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: modify, customize + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- + +In this guide, you can learn how to use the {+driver-short+} to perform +**transactions**. :manual:`Transactions ` allow +you to run a series of operations that do not change any data until the +transaction is committed. If any operation in the transaction returns an +error, the driver cancels the transaction and discards all data changes +before they ever become visible. + +In MongoDB, transactions run within logical **sessions**. A +:manual:`session ` is a grouping of related +read or write operations that you intend to run sequentially. Sessions +enable :manual:`causal consistency +` for a +group of operations or allow you to execute operations in an +:website:`ACID transaction `. MongoDB +guarantees that the data involved in your transaction operations remains +consistent, even if the operations encounter unexpected errors. + +When using the {+driver-short+}, you can create a new session from a +``Client`` instance as a ``ClientSession``. We recommend that you reuse +your client for multiple sessions and transactions instead of +instantiating a new client each time. + +.. warning:: + + Use a ``Session`` only with the ``Client`` (or associated + ``Database`` or ``Collection``) that created it. Using a + ``Session`` with a different ``Client`` results in operation + errors. + +Methods +------- + +Create a ``ClientSession`` by using the ``startSession()`` method on your +``Client`` instance. You can then modify the session state by using the +following methods: + +.. list-table:: + :widths: 25 75 + :header-rows: 1 + + * - Method + - Description + + * - ``startTransaction()`` + - | Starts a new transaction for this session with the + default transaction options. You cannot start a + transaction if there's already an active transaction + on the session. + | + | To set transaction options, use ``startTransaction(transactionOptions: TransactionOptions)``. + + * - ``abortTransaction()`` + - | Ends the active transaction for this session. Returns an error + if there is no active transaction for the + session or the transaction was previously ended. + + * - ``commitTransaction()`` + - | Commits the active transaction for this session. Returns an + error if there is no active transaction for the session or if the + transaction was ended. + + * - ``endSession()`` + - | Ends any existing transactions and closes the session. + +A ``Session`` also has methods to retrieve session properties and modify +mutable session properties. View the `API documentation<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ +to learn more about these methods. + +Example +------- + +The following example demonstrates how you can create a session, create a transaction, +and commit a changes to existing documents: + +1. Create a session from the client using the ``startSession()`` method. +#. Use the ``startTransaction()`` method to start a transaction. +#. Update the specified documents, then use the ``commitTransaction()`` method if all + operations succeed, or ``abortTransaction()`` if any operations fail. + +.. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction.kt + :start-after: start-data-class + :end-before: end-data-class + :language: kotlin + :copyable: + +Additional Information +---------------------- + +To learn more about the concepts mentioned in this guide, see the following pages in +the Server manual: + +- :manual:`Transactions` +- :manual:`Server Sessions` +- :manual:`/core/read-isolation-consistency-recency/#causal-consistency` + +To learn more about ACID compliance, see the `What are ACID properties in Database Management Systems?` +article on the MongoDB website. + +API Documentation +~~~~~~~~~~~~~~~~~ + +To learn more about any of the types or methods discussed in this +guide, see the following API Documentation: + +- `ClientSession<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html}>`__ +- `startTransaction<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/start-transaction.html}>`__ +- `commitTransaction<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/commit-transaction.html}>`__ +- `abortTransaction<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/abort-transaction.html}>`__ From 3dad25228145d257db308dc735da511955e323f7 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 13:07:58 -0700 Subject: [PATCH 02/20] update include --- source/fundamentals/transactions.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index b53e72df..9c2863e9 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -100,8 +100,6 @@ and commit a changes to existing documents: operations succeed, or ``abortTransaction()`` if any operations fail. .. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction.kt - :start-after: start-data-class - :end-before: end-data-class :language: kotlin :copyable: From 0c3d7b983c4a2dfe2eab789135b31ebe200c52af Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 13:13:53 -0700 Subject: [PATCH 03/20] update links --- .../TransactionsTest.snippet.transaction.kt | 14 ++++++++------ source/fundamentals/transactions.txt | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/source/examples/generated/TransactionsTest.snippet.transaction.kt b/source/examples/generated/TransactionsTest.snippet.transaction.kt index b71360de..ff33ce2d 100644 --- a/source/examples/generated/TransactionsTest.snippet.transaction.kt +++ b/source/examples/generated/TransactionsTest.snippet.transaction.kt @@ -18,14 +18,16 @@ suspend fun performTransaction(client: CoroutineClient) { CheckingAccount::accountId eq "9876", inc(CheckingAccount::amount, 100) ) - // Commit the transaction - session.commitTransaction() - println("Transaction committed.") + // Commit the transaction + session.commitTransaction() + println("Transaction committed.") } catch (error: Exception) { - println("An error occurred during the transaction: ${error.message}") - session.abortTransaction() // Abort the transaction + println("An error occurred during the transaction: ${error.message}") + // Abort the transaction + session.abortTransaction() } finally { - session.endSession() // End the session + // End the session + session.endSession() } } } diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 9c2863e9..a141bcc2 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -85,7 +85,7 @@ following methods: - | Ends any existing transactions and closes the session. A ``Session`` also has methods to retrieve session properties and modify -mutable session properties. View the `API documentation<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ +mutable session properties. View the `API documentation<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ to learn more about these methods. Example @@ -111,7 +111,7 @@ the Server manual: - :manual:`Transactions` - :manual:`Server Sessions` -- :manual:`/core/read-isolation-consistency-recency/#causal-consistency` +- :manual:`Read Isolation, Consistency, and Recency` To learn more about ACID compliance, see the `What are ACID properties in Database Management Systems?` article on the MongoDB website. @@ -122,7 +122,7 @@ API Documentation To learn more about any of the types or methods discussed in this guide, see the following API Documentation: -- `ClientSession<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html}>`__ -- `startTransaction<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/start-transaction.html}>`__ -- `commitTransaction<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/commit-transaction.html}>`__ -- `abortTransaction<{+api+/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/abort-transaction.html}>`__ +- `ClientSession<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ +- `startTransaction<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/start-transaction.html>`__ +- `commitTransaction<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/commit-transaction.html>`__ +- `abortTransaction<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/abort-transaction.html>`__ From c30536ef66462fd4927a7244617fdc5e42b21960 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 13:19:02 -0700 Subject: [PATCH 04/20] fix typo --- source/fundamentals/transactions.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index a141bcc2..00bb8e30 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -85,7 +85,7 @@ following methods: - | Ends any existing transactions and closes the session. A ``Session`` also has methods to retrieve session properties and modify -mutable session properties. View the `API documentation<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ +mutable session properties. View the `API documentation <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ to learn more about these methods. Example @@ -109,9 +109,9 @@ Additional Information To learn more about the concepts mentioned in this guide, see the following pages in the Server manual: -- :manual:`Transactions` -- :manual:`Server Sessions` -- :manual:`Read Isolation, Consistency, and Recency` +- :manual:`Transactions ` +- :manual:`Server Sessions ` +- :manual:`Read Isolation, Consistency, and Recency ` To learn more about ACID compliance, see the `What are ACID properties in Database Management Systems?` article on the MongoDB website. @@ -122,7 +122,7 @@ API Documentation To learn more about any of the types or methods discussed in this guide, see the following API Documentation: -- `ClientSession<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ -- `startTransaction<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/start-transaction.html>`__ -- `commitTransaction<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/commit-transaction.html>`__ -- `abortTransaction<{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/abort-transaction.html>`__ +- `ClientSession <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ +- `startTransaction <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/start-transaction.html>`__ +- `commitTransaction <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/commit-transaction.html>`__ +- `abortTransaction <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/abort-transaction.html>`__ From 71ddcf916607c4754f7f4b5d4f06d5fbbf356edc Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 13:23:00 -0700 Subject: [PATCH 05/20] add spacing --- source/fundamentals/transactions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 00bb8e30..3f47d3b3 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -113,7 +113,7 @@ the Server manual: - :manual:`Server Sessions ` - :manual:`Read Isolation, Consistency, and Recency ` -To learn more about ACID compliance, see the `What are ACID properties in Database Management Systems?` +To learn more about ACID compliance, see the `What are ACID properties in Database Management Systems? ` article on the MongoDB website. API Documentation From 800c43a6caae84a848550dfb0c2a88683f59f2ce Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 13:26:20 -0700 Subject: [PATCH 06/20] update website link --- source/fundamentals/transactions.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 3f47d3b3..493d9160 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -113,7 +113,8 @@ the Server manual: - :manual:`Server Sessions ` - :manual:`Read Isolation, Consistency, and Recency ` -To learn more about ACID compliance, see the `What are ACID properties in Database Management Systems? ` +To learn more about ACID compliance, see the :website:`What are ACID +Properties in Database Management Systems? ` article on the MongoDB website. API Documentation From 90daadfa7f6095ba4f9ed60644e359ee3c22a477 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 14:13:23 -0700 Subject: [PATCH 07/20] update code example --- .../generated/TransactionsTest.snippet.transaction.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/source/examples/generated/TransactionsTest.snippet.transaction.kt b/source/examples/generated/TransactionsTest.snippet.transaction.kt index ff33ce2d..630df7c8 100644 --- a/source/examples/generated/TransactionsTest.snippet.transaction.kt +++ b/source/examples/generated/TransactionsTest.snippet.transaction.kt @@ -1,12 +1,12 @@ // Set up the MongoDB client and get the collection -suspend fun performTransaction(client: CoroutineClient) { - client.startSession().use { session: ClientSession -> +suspend fun performTransaction(client: MongoClient) { + client.startSession().use { session -> session.startTransaction() // Start the transaction try { val database = client.getDatabase("bank") val savingsColl = database.getCollection("savings_accounts") - savingsColl.findeOneAndUpdate( + savingsColl.findOneAndUpdate( session, SavingsAccount::accountId eq "9876", inc(SavingsAccount::amount, -100) @@ -25,9 +25,6 @@ suspend fun performTransaction(client: CoroutineClient) { println("An error occurred during the transaction: ${error.message}") // Abort the transaction session.abortTransaction() - } finally { - // End the session - session.endSession() } } } From 8bb6af1bd7d07cfd6327822d141a9eefb177aeb9 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 30 Jul 2024 14:35:49 -0700 Subject: [PATCH 08/20] remove extra reference --- source/fundamentals/transactions.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 493d9160..338abfea 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -80,9 +80,6 @@ following methods: - | Commits the active transaction for this session. Returns an error if there is no active transaction for the session or if the transaction was ended. - - * - ``endSession()`` - - | Ends any existing transactions and closes the session. A ``Session`` also has methods to retrieve session properties and modify mutable session properties. View the `API documentation <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ From 795e1fd95bc1664288c06c7342f54b845d374e42 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Wed, 31 Jul 2024 09:41:57 -0700 Subject: [PATCH 09/20] update code examples --- .../TransactionsTest.snippet.transaction.kt | 13 +++---------- source/fundamentals/transactions.txt | 7 +++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/examples/generated/TransactionsTest.snippet.transaction.kt b/source/examples/generated/TransactionsTest.snippet.transaction.kt index 630df7c8..3f65cbf8 100644 --- a/source/examples/generated/TransactionsTest.snippet.transaction.kt +++ b/source/examples/generated/TransactionsTest.snippet.transaction.kt @@ -1,7 +1,8 @@ // Set up the MongoDB client and get the collection suspend fun performTransaction(client: MongoClient) { client.startSession().use { session -> - session.startTransaction() // Start the transaction + // Start the transaction + session.startTransaction() try { val database = client.getDatabase("bank") @@ -18,6 +19,7 @@ suspend fun performTransaction(client: MongoClient) { CheckingAccount::accountId eq "9876", inc(CheckingAccount::amount, 100) ) + // Commit the transaction session.commitTransaction() println("Transaction committed.") @@ -28,12 +30,3 @@ suspend fun performTransaction(client: MongoClient) { } } } - -data class SavingsAccount(val accountId: String, val amount: Int) -data class CheckingAccount(val accountId: String, val amount: Int) - -fun main() = runBlocking { - val uri = "" - val client = MongoClient.create(uri) - performTransaction(client) -} diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 338abfea..5f348e3e 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -96,6 +96,13 @@ and commit a changes to existing documents: #. Update the specified documents, then use the ``commitTransaction()`` method if all operations succeed, or ``abortTransaction()`` if any operations fail. +This example uses the following {+language+} data classes to model its documents: + +.. code-block:: kotlin + + data class SavingsAccount(val accountId: String, val amount: Int) + data class CheckingAccount(val accountId: String, val amount: Int) + .. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction.kt :language: kotlin :copyable: From e9b22ad767fe7020bda04c74f3439b0642f77e69 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Wed, 31 Jul 2024 09:58:21 -0700 Subject: [PATCH 10/20] use include --- .../generated/TransactionsTest.snippet.data-class.kt | 3 +++ source/fundamentals/transactions.txt | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 source/examples/generated/TransactionsTest.snippet.data-class.kt diff --git a/source/examples/generated/TransactionsTest.snippet.data-class.kt b/source/examples/generated/TransactionsTest.snippet.data-class.kt new file mode 100644 index 00000000..3b877447 --- /dev/null +++ b/source/examples/generated/TransactionsTest.snippet.data-class.kt @@ -0,0 +1,3 @@ + data class SavingsAccount(val accountId: String, val amount: Int) + data class CheckingAccount(val accountId: String, val amount: Int) + \ No newline at end of file diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 5f348e3e..88c9a6e6 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -98,10 +98,9 @@ and commit a changes to existing documents: This example uses the following {+language+} data classes to model its documents: -.. code-block:: kotlin - - data class SavingsAccount(val accountId: String, val amount: Int) - data class CheckingAccount(val accountId: String, val amount: Int) +.. literalinclude:: /examples/generated/TransactionsTest.snippet.data-class.kt + :language: kotlin + :copyable: .. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction.kt :language: kotlin From 150f9fb601c81d7d4193dcece624e2e3c9504c3a Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Wed, 31 Jul 2024 11:09:51 -0700 Subject: [PATCH 11/20] update constant --- source/fundamentals/transactions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 88c9a6e6..dd5f3141 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -96,7 +96,7 @@ and commit a changes to existing documents: #. Update the specified documents, then use the ``commitTransaction()`` method if all operations succeed, or ``abortTransaction()`` if any operations fail. -This example uses the following {+language+} data classes to model its documents: +This example uses the following {+driver+} data classes to model its documents: .. literalinclude:: /examples/generated/TransactionsTest.snippet.data-class.kt :language: kotlin From 07d902b8dc8333bb123c21462e9e00a5a002b29d Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Wed, 31 Jul 2024 11:15:22 -0700 Subject: [PATCH 12/20] update source constants --- snooty.toml | 1 + source/fundamentals/transactions.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/snooty.toml b/snooty.toml index 16fdb108..85b277f7 100644 --- a/snooty.toml +++ b/snooty.toml @@ -21,6 +21,7 @@ driver-short = "Kotlin driver" driver-long = "MongoDB Kotlin Driver" version = "5.1" full-version = "{+version+}.2" +language = "Kotlin" mdb-server = "MongoDB server" kotlin-docs = "https://kotlinlang.org" diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index dd5f3141..88c9a6e6 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -96,7 +96,7 @@ and commit a changes to existing documents: #. Update the specified documents, then use the ``commitTransaction()`` method if all operations succeed, or ``abortTransaction()`` if any operations fail. -This example uses the following {+driver+} data classes to model its documents: +This example uses the following {+language+} data classes to model its documents: .. literalinclude:: /examples/generated/TransactionsTest.snippet.data-class.kt :language: kotlin From cf348248ec23fb4352f8d91df6b03d0a92adacaf Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Wed, 31 Jul 2024 15:10:10 -0700 Subject: [PATCH 13/20] update code examples and references --- examples/src/test/kotlin/TransactionsTest.kt | 86 +++++++++++++++++++ .../TransactionsTest.snippet.data-class.kt | 7 +- ...ctionsTest.snippet.transaction-function.kt | 31 +++++++ .../TransactionsTest.snippet.transaction.kt | 32 ------- source/fundamentals/transactions.txt | 4 +- 5 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 examples/src/test/kotlin/TransactionsTest.kt create mode 100644 source/examples/generated/TransactionsTest.snippet.transaction-function.kt delete mode 100644 source/examples/generated/TransactionsTest.snippet.transaction.kt diff --git a/examples/src/test/kotlin/TransactionsTest.kt b/examples/src/test/kotlin/TransactionsTest.kt new file mode 100644 index 00000000..dfd758bd --- /dev/null +++ b/examples/src/test/kotlin/TransactionsTest.kt @@ -0,0 +1,86 @@ +import com.mongodb.kotlin.client.coroutine.MongoClient +import com.mongodb.client.model.Filters.eq +import com.mongodb.client.model.Updates.inc +import config.getConfig +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class TransactionsTest { + + // :snippet-start: data-class + data class Account( + val accountId: String, + val amount: Int + ) + // :snippet-end: + + companion object { + val config = getConfig() + val client = MongoClient.create(config.connectionUri) + val database = client.getDatabase("bank") + + @BeforeAll + @JvmStatic + fun beforeAll() { + runBlocking { + val savAcct = Account("9876", 900) + database.getCollection("savings_accounts").insertOne(savAcct) + + val chkAcct = Account("9876", 50) + database.getCollection("checking_accounts").insertOne(chkAcct) + } + } + + @AfterAll + @JvmStatic + fun afterAll() { + runBlocking { + database.drop() + client.close() + } + } + } + + @Test + fun transactionTest() = runBlocking { + // :snippet-start: transaction-function + // Set up the session + val session = client.startSession() + + try { + session.startTransaction() + + val savingsColl = database + .getCollection("savings_accounts") + val checkingColl = database + .getCollection("checking_accounts") + + savingsColl.findOneAndUpdate( + session, + eq(Account::accountId.name, "9876"), + inc(Account::amount.name, -100), + ) + + checkingColl.findOneAndUpdate( + session, + eq(Account::accountId.name, "9876"), + inc(Account::amount.name, 100) + ) + + // Commit the transaction + val result = session.commitTransaction() + println("Transaction committed.") + assertNotNull(result) // :remove: + } catch (error: Exception) { + println("An error occurred during the transaction: ${error.message}") + // Abort the transaction + session.abortTransaction() + } + // :snippet-end: + } +} diff --git a/source/examples/generated/TransactionsTest.snippet.data-class.kt b/source/examples/generated/TransactionsTest.snippet.data-class.kt index 3b877447..45f6c152 100644 --- a/source/examples/generated/TransactionsTest.snippet.data-class.kt +++ b/source/examples/generated/TransactionsTest.snippet.data-class.kt @@ -1,3 +1,4 @@ - data class SavingsAccount(val accountId: String, val amount: Int) - data class CheckingAccount(val accountId: String, val amount: Int) - \ No newline at end of file +data class Account( + val accountId: String, + val amount: Int +) diff --git a/source/examples/generated/TransactionsTest.snippet.transaction-function.kt b/source/examples/generated/TransactionsTest.snippet.transaction-function.kt new file mode 100644 index 00000000..2ce7b0b5 --- /dev/null +++ b/source/examples/generated/TransactionsTest.snippet.transaction-function.kt @@ -0,0 +1,31 @@ +// Set up the session +val session = client.startSession() + +try { + session.startTransaction() + + val savingsColl = database + .getCollection("savings_accounts") + val checkingColl = database + .getCollection("checking_accounts") + + savingsColl.findOneAndUpdate( + session, + eq(Account::accountId.name, "9876"), + inc(Account::amount.name, -100), + ) + + checkingColl.findOneAndUpdate( + session, + eq(Account::accountId.name, "9876"), + inc(Account::amount.name, 100) + ) + + // Commit the transaction + val result = session.commitTransaction() + println("Transaction committed.") +} catch (error: Exception) { + println("An error occurred during the transaction: ${error.message}") + // Abort the transaction + session.abortTransaction() +} diff --git a/source/examples/generated/TransactionsTest.snippet.transaction.kt b/source/examples/generated/TransactionsTest.snippet.transaction.kt deleted file mode 100644 index 3f65cbf8..00000000 --- a/source/examples/generated/TransactionsTest.snippet.transaction.kt +++ /dev/null @@ -1,32 +0,0 @@ -// Set up the MongoDB client and get the collection -suspend fun performTransaction(client: MongoClient) { - client.startSession().use { session -> - // Start the transaction - session.startTransaction() - try { - val database = client.getDatabase("bank") - - val savingsColl = database.getCollection("savings_accounts") - savingsColl.findOneAndUpdate( - session, - SavingsAccount::accountId eq "9876", - inc(SavingsAccount::amount, -100) - ) - - val checkingColl = database.getCollection("checking_accounts") - checkingColl.findOneAndUpdate( - session, - CheckingAccount::accountId eq "9876", - inc(CheckingAccount::amount, 100) - ) - - // Commit the transaction - session.commitTransaction() - println("Transaction committed.") - } catch (error: Exception) { - println("An error occurred during the transaction: ${error.message}") - // Abort the transaction - session.abortTransaction() - } - } -} diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index 88c9a6e6..f69b259c 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -100,11 +100,9 @@ This example uses the following {+language+} data classes to model its documents .. literalinclude:: /examples/generated/TransactionsTest.snippet.data-class.kt :language: kotlin - :copyable: -.. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction.kt +.. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction-function.kt :language: kotlin - :copyable: Additional Information ---------------------- From ff52fb1021c3aef44e97b0dd408718bcf3b5f1a3 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Tue, 20 Aug 2024 09:36:06 -0700 Subject: [PATCH 14/20] update code intros --- source/fundamentals/transactions.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index f69b259c..be271c8a 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -88,19 +88,19 @@ to learn more about these methods. Example ------- +This example uses the following {+language+} data class to model its documents: + +.. literalinclude:: /examples/generated/TransactionsTest.snippet.data-class.kt + :language: kotlin + The following example demonstrates how you can create a session, create a transaction, -and commit a changes to existing documents: +and commit changes to existing documents: 1. Create a session from the client using the ``startSession()`` method. #. Use the ``startTransaction()`` method to start a transaction. #. Update the specified documents, then use the ``commitTransaction()`` method if all operations succeed, or ``abortTransaction()`` if any operations fail. -This example uses the following {+language+} data classes to model its documents: - -.. literalinclude:: /examples/generated/TransactionsTest.snippet.data-class.kt - :language: kotlin - .. literalinclude:: /examples/generated/TransactionsTest.snippet.transaction-function.kt :language: kotlin From 43247431e1b2e8caf5e64972a131af90583ac4f9 Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Mon, 5 Aug 2024 14:50:26 -0400 Subject: [PATCH 15/20] DOCSP-42086: server 8.0 compat (#168) --- .../mongodb-compatibility-table-kotlin.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/includes/mongodb-compatibility-table-kotlin.rst b/source/includes/mongodb-compatibility-table-kotlin.rst index 745cfe59..f753bcf3 100644 --- a/source/includes/mongodb-compatibility-table-kotlin.rst +++ b/source/includes/mongodb-compatibility-table-kotlin.rst @@ -4,6 +4,7 @@ :class: compatibility-large * - Kotlin Driver Version + - MongoDB 8.0 - MongoDB 7.0 - MongoDB 6.0 - MongoDB 5.0 @@ -16,7 +17,22 @@ - MongoDB 3.0 - MongoDB 2.6 + * - 5.2 + - ✓ + - ✓ + - ✓ + - ✓ + - ✓ + - ✓ + - ✓ + - ✓ + - + - + - + - + * - 5.1 + - ⊛ - ✓ - ✓ - ✓ @@ -30,6 +46,7 @@ - * - 5.0 + - ⊛ - ✓ - ✓ - ✓ @@ -43,6 +60,7 @@ - * - 4.11 + - ⊛ - ✓ - ✓ - ✓ @@ -56,6 +74,7 @@ - * - 4.10 + - ⊛ - ✓ - ✓ - ✓ From 31cb0e916936ba379b0334cbf483df9d92010e7a Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:44:43 -0400 Subject: [PATCH 16/20] DOCSP-42514: kotlin user/pass placeholders (#169) --- examples/src/test/kotlin/AuthTest.kt | 12 ++++----- .../src/test/kotlin/EnterpriseAuthTest.kt | 25 ++++++++++--------- .../test/kotlin/MongoClientSettingsTest.kt | 2 +- source/connection-troubleshooting.txt | 2 +- .../AuthTest.snippet.default-cred-string.kt | 2 +- .../AuthTest.snippet.default-mongo-cred.kt | 2 +- .../AuthTest.snippet.scram-sha-1-cred.kt | 2 +- .../AuthTest.snippet.scram-sha-1-string.kt | 2 +- .../AuthTest.snippet.scram-sha-256-cred.kt | 2 +- .../AuthTest.snippet.scram-sha-256-string.kt | 2 +- .../AuthTest.snippet.x-509-string.kt | 2 +- ...priseAuthTest.snippet.auth-creds-gssapi.kt | 2 +- ...thTest.snippet.gssapi-connection-string.kt | 2 +- ...pet.gssapi-properties-connection-string.kt | 2 +- ...rpriseAuthTest.snippet.java-subject-key.kt | 2 +- ...hTest.snippet.kerberos-subject-provider.kt | 2 +- ...AuthTest.snippet.ldap-connection-string.kt | 2 +- ...eAuthTest.snippet.ldap-mongo-credential.kt | 2 +- ...st.snippet.oidc-azure-connection-string.kt | 2 +- ...eAuthTest.snippet.oidc-azure-credential.kt | 2 +- ...Test.snippet.oidc-gcp-connection-string.kt | 2 +- ...iseAuthTest.snippet.oidc-gcp-credential.kt | 2 +- ...rpriseAuthTest.snippet.service-name-key.kt | 2 +- ...t.snippet.chain-order-connection-string.kt | 2 +- source/fundamentals/auth.txt | 12 ++++----- source/fundamentals/connection/connect.txt | 2 +- source/fundamentals/enterprise-auth.txt | 6 ++--- 27 files changed, 51 insertions(+), 50 deletions(-) diff --git a/examples/src/test/kotlin/AuthTest.kt b/examples/src/test/kotlin/AuthTest.kt index 70272c94..47e70ab5 100644 --- a/examples/src/test/kotlin/AuthTest.kt +++ b/examples/src/test/kotlin/AuthTest.kt @@ -47,7 +47,7 @@ internal class AuthTest { fun defaultConnectionStringTest() = runBlocking { // :replace-start: { // "terms": { - // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=\"" + // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=\"" // } // } // :snippet-start: default-cred-string @@ -70,7 +70,7 @@ internal class AuthTest { fun scramSha256ConnectionStringTest() = runBlocking { // :replace-start: { // "terms": { - // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-256\"" + // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-256\"" // } // } // :snippet-start: scram-sha-256-string @@ -93,7 +93,7 @@ internal class AuthTest { fun scramSha1ConnectionStringTest() = runBlocking { // :replace-start: { // "terms": { - // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-1\"" + // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-1\"" // } // } // :snippet-start: scram-sha-1-string @@ -116,7 +116,7 @@ internal class AuthTest { fun x509ConnectionStringTest() = runBlocking { // :replace-start: { // "terms": { - // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=&authMechanism=MONGODB-X509&tls=true\"" + // "CONNECTION_URI_PLACEHOLDER": "\"mongodb://:@:/?authSource=&authMechanism=MONGODB-X509&tls=true\"" // } // } // :snippet-start: x-509-string @@ -137,8 +137,8 @@ internal class AuthTest { // :replace-start: { // "terms": { - // "USERNAME": "\"\"", - // "PASSWORD": "\"\"", + // "USERNAME": "\"\"", + // "PASSWORD": "\"\"", // "AUTH_DB": "\"\"", // "HOSTNAME": "\"\"", // "PORT": "\"\"" diff --git a/examples/src/test/kotlin/EnterpriseAuthTest.kt b/examples/src/test/kotlin/EnterpriseAuthTest.kt index c30ee505..3a955484 100644 --- a/examples/src/test/kotlin/EnterpriseAuthTest.kt +++ b/examples/src/test/kotlin/EnterpriseAuthTest.kt @@ -13,6 +13,7 @@ import javax.naming.Context import javax.security.auth.Subject import javax.security.auth.login.LoginContext import kotlin.test.Ignore + // :replace-start: { // "terms": { // "PORT": "", @@ -36,7 +37,7 @@ internal class EnterpriseAuthTest { fun createGSSAPICred() = runBlocking { // :snippet-start: auth-creds-gssapi - val credential = MongoCredential.createGSSAPICredential("") + val credential = MongoCredential.createGSSAPICredential("") val settings = MongoClientSettings.builder() .applyToClusterSettings { builder -> @@ -51,7 +52,7 @@ internal class EnterpriseAuthTest { fun serviceNameKey() = runBlocking { // :snippet-start: service-name-key - val credential = MongoCredential.createGSSAPICredential("") + val credential = MongoCredential.createGSSAPICredential("") .withMechanismProperty(MongoCredential.SERVICE_NAME_KEY, "myService") // :snippet-end: } @@ -62,7 +63,7 @@ internal class EnterpriseAuthTest { loginContext.login() val subject: Subject = loginContext.subject - val credential = MongoCredential.createGSSAPICredential("") + val credential = MongoCredential.createGSSAPICredential("") .withMechanismProperty(MongoCredential.JAVA_SUBJECT_KEY, subject) // :snippet-end: } @@ -74,7 +75,7 @@ internal class EnterpriseAuthTest { val myLoginContext = "myContext" /* Login context defaults to "com.sun.security.jgss.krb5.initiate" if unspecified in KerberosSubjectProvider */ - val credential = MongoCredential.createGSSAPICredential("") + val credential = MongoCredential.createGSSAPICredential("") .withMechanismProperty( MongoCredential.JAVA_SUBJECT_PROVIDER_KEY, KerberosSubjectProvider(myLoginContext) @@ -84,7 +85,7 @@ internal class EnterpriseAuthTest { fun ldapCredential() = runBlocking { // :snippet-start: ldap-mongo-credential - val credential = MongoCredential.createPlainCredential("", "$external", "".toCharArray()) + val credential = MongoCredential.createPlainCredential("", "$external", "".toCharArray()) val settings = MongoClientSettings.builder() .applyToClusterSettings { builder -> @@ -99,21 +100,21 @@ internal class EnterpriseAuthTest { fun gssapiConnectionString() = runBlocking { // :snippet-start: gssapi-connection-string - val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI") + val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI") val mongoClient = MongoClient.create(connectionString) // :snippet-end: } fun gssapiPropertiesConnectionString() = runBlocking { // :snippet-start: gssapi-properties-connection-string - val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:myService") + val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:myService") val mongoClient = MongoClient.create(connectionString) // :snippet-end: } fun ldapConnectionString() = runBlocking { // :snippet-start: ldap-connection-string - val connectionString = ConnectionString(":@:/?authSource=$external&authMechanism=PLAIN") + val connectionString = ConnectionString(":@:/?authSource=$external&authMechanism=PLAIN") val mongoClient = MongoClient.create(connectionString) // :snippet-end: } @@ -121,7 +122,7 @@ internal class EnterpriseAuthTest { fun oidcAzureConnectionString() = runBlocking { // :snippet-start: oidc-azure-connection-string val connectionString = ConnectionString( - "mongodb://@:/?" + + "mongodb://@:/?" + "?authMechanism=MONGODB-OIDC" + "&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:") val mongoClient = MongoClient.create(connectionString) @@ -130,7 +131,7 @@ internal class EnterpriseAuthTest { fun oidcAzureCredential() = runBlocking { // :snippet-start: oidc-azure-credential - val credential = MongoCredential.createOidcCredential("") + val credential = MongoCredential.createOidcCredential("") .withMechanismProperty("ENVIRONMENT", "azure") .withMechanismProperty("TOKEN_RESOURCE", "") @@ -147,7 +148,7 @@ internal class EnterpriseAuthTest { fun oidcGCPConnectionString() = runBlocking { // :snippet-start: oidc-gcp-connection-string val connectionString = ConnectionString( - "mongodb://:/?" + + "mongodb://@:/?" + "authMechanism=MONGODB-OIDC" + "&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:") val mongoClient = MongoClient.create(connectionString) @@ -156,7 +157,7 @@ internal class EnterpriseAuthTest { fun oidcGCPCredential() = runBlocking { // :snippet-start: oidc-gcp-credential - val credential = MongoCredential.createOidcCredential("") + val credential = MongoCredential.createOidcCredential("") .withMechanismProperty("ENVIRONMENT", "gcp") .withMechanismProperty("TOKEN_RESOURCE", "") diff --git a/examples/src/test/kotlin/MongoClientSettingsTest.kt b/examples/src/test/kotlin/MongoClientSettingsTest.kt index ceff28d8..b8d8de9d 100644 --- a/examples/src/test/kotlin/MongoClientSettingsTest.kt +++ b/examples/src/test/kotlin/MongoClientSettingsTest.kt @@ -16,7 +16,7 @@ import kotlin.test.Ignore // :replace-start: { // "terms": { // "uri": "\"\"", -// "uriString": "\"mongodb+srv:/:@:?connectTimeoutMS(2000)\"", +// "uriString": "\"mongodb+srv:/:@:?connectTimeoutMS(2000)\"", // "uriAcmeString": "\"mongodb+srv://host1.acme.com\"" // } // } diff --git a/source/connection-troubleshooting.txt b/source/connection-troubleshooting.txt index a6098d4a..1d2d7e2b 100644 --- a/source/connection-troubleshooting.txt +++ b/source/connection-troubleshooting.txt @@ -127,7 +127,7 @@ database: :copyable: false val mongoClient = - MongoClient.create("mongodb://:@:/?authSource=users") + MongoClient.create("mongodb://:@:/?authSource=users") .. _kotlin-error-sending-message: diff --git a/source/examples/generated/AuthTest.snippet.default-cred-string.kt b/source/examples/generated/AuthTest.snippet.default-cred-string.kt index f766df60..248c6bdc 100644 --- a/source/examples/generated/AuthTest.snippet.default-cred-string.kt +++ b/source/examples/generated/AuthTest.snippet.default-cred-string.kt @@ -1,2 +1,2 @@ val mongoClient = - MongoClient.create("mongodb://:@:/?authSource=") + MongoClient.create("mongodb://:@:/?authSource=") diff --git a/source/examples/generated/AuthTest.snippet.default-mongo-cred.kt b/source/examples/generated/AuthTest.snippet.default-mongo-cred.kt index 49f6fe47..19cfdc69 100644 --- a/source/examples/generated/AuthTest.snippet.default-mongo-cred.kt +++ b/source/examples/generated/AuthTest.snippet.default-mongo-cred.kt @@ -1,5 +1,5 @@ val credential = MongoCredential.createCredential( - "", "", "".toCharArray() + "", "", "".toCharArray() ) val settings = MongoClientSettings.builder() .applyToClusterSettings { builder: ClusterSettings.Builder -> diff --git a/source/examples/generated/AuthTest.snippet.scram-sha-1-cred.kt b/source/examples/generated/AuthTest.snippet.scram-sha-1-cred.kt index 774c5d8e..9db847d6 100644 --- a/source/examples/generated/AuthTest.snippet.scram-sha-1-cred.kt +++ b/source/examples/generated/AuthTest.snippet.scram-sha-1-cred.kt @@ -1,5 +1,5 @@ val credential = MongoCredential.createScramSha1Credential( - "", "", "".toCharArray() + "", "", "".toCharArray() ) val settings = MongoClientSettings.builder() .applyToClusterSettings { builder: ClusterSettings.Builder -> diff --git a/source/examples/generated/AuthTest.snippet.scram-sha-1-string.kt b/source/examples/generated/AuthTest.snippet.scram-sha-1-string.kt index 5eebaa06..e2e0ff14 100644 --- a/source/examples/generated/AuthTest.snippet.scram-sha-1-string.kt +++ b/source/examples/generated/AuthTest.snippet.scram-sha-1-string.kt @@ -1,2 +1,2 @@ val mongoClient = - MongoClient.create("mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-1") + MongoClient.create("mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-1") diff --git a/source/examples/generated/AuthTest.snippet.scram-sha-256-cred.kt b/source/examples/generated/AuthTest.snippet.scram-sha-256-cred.kt index b7f49371..ad480671 100644 --- a/source/examples/generated/AuthTest.snippet.scram-sha-256-cred.kt +++ b/source/examples/generated/AuthTest.snippet.scram-sha-256-cred.kt @@ -1,5 +1,5 @@ val credential = MongoCredential.createScramSha256Credential( - "", "", "".toCharArray() + "", "", "".toCharArray() ) val settings = MongoClientSettings.builder() .applyToClusterSettings { builder: ClusterSettings.Builder -> diff --git a/source/examples/generated/AuthTest.snippet.scram-sha-256-string.kt b/source/examples/generated/AuthTest.snippet.scram-sha-256-string.kt index 43ae188c..36d38fcd 100644 --- a/source/examples/generated/AuthTest.snippet.scram-sha-256-string.kt +++ b/source/examples/generated/AuthTest.snippet.scram-sha-256-string.kt @@ -1,2 +1,2 @@ val mongoClient = - MongoClient.create("mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-256") + MongoClient.create("mongodb://:@:/?authSource=&authMechanism=SCRAM-SHA-256") diff --git a/source/examples/generated/AuthTest.snippet.x-509-string.kt b/source/examples/generated/AuthTest.snippet.x-509-string.kt index fcdfb9b5..04fffb88 100644 --- a/source/examples/generated/AuthTest.snippet.x-509-string.kt +++ b/source/examples/generated/AuthTest.snippet.x-509-string.kt @@ -1,2 +1,2 @@ val mongoClient = - MongoClient.create("mongodb://:@:/?authSource=&authMechanism=MONGODB-X509&tls=true") + MongoClient.create("mongodb://:@:/?authSource=&authMechanism=MONGODB-X509&tls=true") diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.auth-creds-gssapi.kt b/source/examples/generated/EnterpriseAuthTest.snippet.auth-creds-gssapi.kt index ec8405b3..d665ddd7 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.auth-creds-gssapi.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.auth-creds-gssapi.kt @@ -1,4 +1,4 @@ -val credential = MongoCredential.createGSSAPICredential("") +val credential = MongoCredential.createGSSAPICredential("") val settings = MongoClientSettings.builder() .applyToClusterSettings { builder -> diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-connection-string.kt b/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-connection-string.kt index 0616d580..a39f8c41 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-connection-string.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-connection-string.kt @@ -1,2 +1,2 @@ -val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI") +val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI") val mongoClient = MongoClient.create(connectionString) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-properties-connection-string.kt b/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-properties-connection-string.kt index c0974bd0..13c58ed7 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-properties-connection-string.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.gssapi-properties-connection-string.kt @@ -1,2 +1,2 @@ -val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:myService") +val connectionString = ConnectionString("@:/?authSource=$external&authMechanism=GSSAPI&authMechanismProperties=SERVICE_NAME:myService") val mongoClient = MongoClient.create(connectionString) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.java-subject-key.kt b/source/examples/generated/EnterpriseAuthTest.snippet.java-subject-key.kt index f2847181..659970c0 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.java-subject-key.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.java-subject-key.kt @@ -2,5 +2,5 @@ val loginContext = LoginContext("") loginContext.login() val subject: Subject = loginContext.subject -val credential = MongoCredential.createGSSAPICredential("") +val credential = MongoCredential.createGSSAPICredential("") .withMechanismProperty(MongoCredential.JAVA_SUBJECT_KEY, subject) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.kerberos-subject-provider.kt b/source/examples/generated/EnterpriseAuthTest.snippet.kerberos-subject-provider.kt index 2687d2e0..018dd14f 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.kerberos-subject-provider.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.kerberos-subject-provider.kt @@ -3,7 +3,7 @@ will share a Kerberos ticket cache */ val myLoginContext = "myContext" /* Login context defaults to "com.sun.security.jgss.krb5.initiate" if unspecified in KerberosSubjectProvider */ -val credential = MongoCredential.createGSSAPICredential("") +val credential = MongoCredential.createGSSAPICredential("") .withMechanismProperty( MongoCredential.JAVA_SUBJECT_PROVIDER_KEY, KerberosSubjectProvider(myLoginContext) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.ldap-connection-string.kt b/source/examples/generated/EnterpriseAuthTest.snippet.ldap-connection-string.kt index c9b40c3f..0d344579 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.ldap-connection-string.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.ldap-connection-string.kt @@ -1,2 +1,2 @@ -val connectionString = ConnectionString(":@:/?authSource=$external&authMechanism=PLAIN") +val connectionString = ConnectionString(":@:/?authSource=$external&authMechanism=PLAIN") val mongoClient = MongoClient.create(connectionString) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.ldap-mongo-credential.kt b/source/examples/generated/EnterpriseAuthTest.snippet.ldap-mongo-credential.kt index 7e769935..9e736a4b 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.ldap-mongo-credential.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.ldap-mongo-credential.kt @@ -1,4 +1,4 @@ -val credential = MongoCredential.createPlainCredential("", "$external", "".toCharArray()) +val credential = MongoCredential.createPlainCredential("", "$external", "".toCharArray()) val settings = MongoClientSettings.builder() .applyToClusterSettings { builder -> diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-connection-string.kt b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-connection-string.kt index d73b0f59..44c940c5 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-connection-string.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-connection-string.kt @@ -1,5 +1,5 @@ val connectionString = ConnectionString( - "mongodb://@:/?" + + "mongodb://@:/?" + "?authMechanism=MONGODB-OIDC" + "&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:") val mongoClient = MongoClient.create(connectionString) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-credential.kt b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-credential.kt index cad36ee2..c9ea75b9 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-credential.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-azure-credential.kt @@ -1,4 +1,4 @@ -val credential = MongoCredential.createOidcCredential("") +val credential = MongoCredential.createOidcCredential("") .withMechanismProperty("ENVIRONMENT", "azure") .withMechanismProperty("TOKEN_RESOURCE", "") diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-connection-string.kt b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-connection-string.kt index 874c7bfe..fc02caf1 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-connection-string.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-connection-string.kt @@ -1,5 +1,5 @@ val connectionString = ConnectionString( - "mongodb://:/?" + + "mongodb://@:/?" + "authMechanism=MONGODB-OIDC" + "&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:") val mongoClient = MongoClient.create(connectionString) diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-credential.kt b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-credential.kt index 3a2d0782..ba27712b 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-credential.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.oidc-gcp-credential.kt @@ -1,4 +1,4 @@ -val credential = MongoCredential.createOidcCredential("") +val credential = MongoCredential.createOidcCredential("") .withMechanismProperty("ENVIRONMENT", "gcp") .withMechanismProperty("TOKEN_RESOURCE", "") diff --git a/source/examples/generated/EnterpriseAuthTest.snippet.service-name-key.kt b/source/examples/generated/EnterpriseAuthTest.snippet.service-name-key.kt index fa1991c3..6ecedb92 100644 --- a/source/examples/generated/EnterpriseAuthTest.snippet.service-name-key.kt +++ b/source/examples/generated/EnterpriseAuthTest.snippet.service-name-key.kt @@ -1,2 +1,2 @@ -val credential = MongoCredential.createGSSAPICredential("") +val credential = MongoCredential.createGSSAPICredential("") .withMechanismProperty(MongoCredential.SERVICE_NAME_KEY, "myService") diff --git a/source/examples/generated/MongoClientSettingsTest.snippet.chain-order-connection-string.kt b/source/examples/generated/MongoClientSettingsTest.snippet.chain-order-connection-string.kt index 042fa21b..b3f89a4b 100644 --- a/source/examples/generated/MongoClientSettingsTest.snippet.chain-order-connection-string.kt +++ b/source/examples/generated/MongoClientSettingsTest.snippet.chain-order-connection-string.kt @@ -1,6 +1,6 @@ val mongoClient = MongoClient.create( MongoClientSettings.builder() - .applyConnectionString(ConnectionString("mongodb+srv:/:@:?connectTimeoutMS(2000)")) + .applyConnectionString(ConnectionString("mongodb+srv:/:@:?connectTimeoutMS(2000)")) .applyToSocketSettings{ builder -> builder.connectTimeout(5, TimeUnit.SECONDS) } diff --git a/source/fundamentals/auth.txt b/source/fundamentals/auth.txt index 2404ecdc..a2372f76 100644 --- a/source/fundamentals/auth.txt +++ b/source/fundamentals/auth.txt @@ -63,8 +63,8 @@ which they advertise support. The following code snippets show how to specify the authentication mechanism, using the following placeholders: -* ``username`` - your MongoDB username -* ``password`` - your MongoDB user's password +* ``db_username`` - your MongoDB database username +* ``db_password`` - your MongoDB database user's password * ``hostname`` - network address of your MongoDB server, accessible by your client * ``port`` - port number of your MongoDB server * ``authenticationDb`` - MongoDB database that contains your user's @@ -120,8 +120,8 @@ algorithm, to authenticate your user. The following code snippets show how to specify the authentication mechanism, using the following placeholders: -* ``username`` - your MongoDB username. -* ``password`` - your MongoDB user's password. +* ``db_username`` - your MongoDB database username. +* ``db_password`` - your MongoDB database user's password. * ``hostname`` - network address of your MongoDB server, accessible by your client. * ``port`` - port number of your MongoDB server. * ``authenticationDb`` - MongoDB database that contains your user's @@ -172,8 +172,8 @@ your user. The following code snippets show how to specify the authentication mechanism, using the following placeholders: -* ``username`` - your MongoDB username. -* ``password`` - your MongoDB user's password. +* ``db_username`` - your MongoDB database username. +* ``db_password`` - your MongoDB database user's password. * ``hostname`` - network address of your MongoDB server, accessible by your client. * ``port`` - port number of your MongoDB server. * ``authenticationDb`` - MongoDB database that contains your user's diff --git a/source/fundamentals/connection/connect.txt b/source/fundamentals/connection/connect.txt index 18e0eabc..78754640 100644 --- a/source/fundamentals/connection/connect.txt +++ b/source/fundamentals/connection/connect.txt @@ -68,7 +68,7 @@ to change the servers in rotation without reconfiguring clients. The next part of the connection URI contains your credentials if you are using a password-based authentication mechanism. Replace the value of ``user`` -with your username and ``pass`` with your password. If your +with your database username and ``pass`` with your database user's password. If your authentication mechanism does not require credentials, omit this part of the connection URI. diff --git a/source/fundamentals/enterprise-auth.txt b/source/fundamentals/enterprise-auth.txt index 1daa1997..defe7000 100644 --- a/source/fundamentals/enterprise-auth.txt +++ b/source/fundamentals/enterprise-auth.txt @@ -66,7 +66,7 @@ principal name. The following code snippets show how to specify the authentication mechanism, using the following placeholders: -* ``username`` - your URL-encoded principal name, e.g. "username%40REALM.ME" +* ``Kerberos principal`` - your URL-encoded principal name, e.g. "username%40REALM.ME" * ``hostname`` - network address of your MongoDB server, accessible by your client * ``port`` - port number of your MongoDB server @@ -248,7 +248,7 @@ parameter to ``PLAIN`` and including your LDAP username and password in the The following code snippets show how to specify the authentication mechanism, using the following placeholders: -* ``username`` - your LDAP username +* ``LDAP username`` - your LDAP username * ``password`` - your LDAP user's password * ``hostname`` - network address of your MongoDB server, accessible by your client * ``port`` - port number of your MongoDB server @@ -344,7 +344,7 @@ see the corresponding syntax. .. tab:: MongoCredential :tabid: mongodb-azure-mongo-credential - Replace the ```` placeholder with the client ID or application ID of the + Replace the ```` placeholder with the client ID or application ID of the Azure managed identity or enterprise application. Replace the ```` placeholder with the value of the ``audience`` server parameter configured on your MongoDB deployment. From 163591b5b105e0e7c79c23e514af16dcc02b70e0 Mon Sep 17 00:00:00 2001 From: Rea Rustagi <85902999+rustagir@users.noreply.github.com> Date: Thu, 15 Aug 2024 09:48:26 -0400 Subject: [PATCH 17/20] DOCSP-42282: java avs type support (#170) --- examples/src/test/kotlin/SearchIndexesTest.kt | 36 ++++++++++++------- ...sTest.snippet.multi-search-index-create.kt | 29 +++++++++------ ...Test.snippet.single-search-index-create.kt | 4 +-- source/fundamentals/indexes.txt | 30 +++++++++------- source/whats-new.txt | 14 ++++++++ 5 files changed, 76 insertions(+), 37 deletions(-) diff --git a/examples/src/test/kotlin/SearchIndexesTest.kt b/examples/src/test/kotlin/SearchIndexesTest.kt index c7d4fcf3..ea6d09c4 100644 --- a/examples/src/test/kotlin/SearchIndexesTest.kt +++ b/examples/src/test/kotlin/SearchIndexesTest.kt @@ -17,6 +17,7 @@ import kotlin.test.assertFalse // "CONNECTION_URI_PLACEHOLDER": "\"\"" // } // } + @TestInstance(TestInstance.Lifecycle.PER_CLASS) class SearchIndexesTest { @@ -42,11 +43,11 @@ class SearchIndexesTest { @Test fun singleSearchIndexTest() = runBlocking { // :snippet-start: single-search-index-create - val index = Document( + val searchIdx = Document( "mappings", Document("dynamic", true) ) - val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index) + val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", searchIdx) // :snippet-end: println("Index created: $resultCreateIndex") assertEquals("myIndex", resultCreateIndex) @@ -56,24 +57,33 @@ class SearchIndexesTest { @Test fun multipleSearchIndexTest() = runBlocking { // :snippet-start: multi-search-index-create - val indexOne = SearchIndexModel( - "myIndex1", + val searchIdxMdl = SearchIndexModel( + "searchIdx", Document("analyzer", "lucene.standard").append( "mappings", Document("dynamic", true) - ) + ), + SearchIndexType.search() ) - val indexTwo = SearchIndexModel( - "myIndex2", - Document("analyzer", "lucene.simple").append( - "mappings", Document("dynamic", true) - ) + val vectorSearchIdxMdl = SearchIndexModel( + "vsIdx", + Document( + "fields", + listOf( + Document("type", "vector") + .append("path", "embeddings") + .append("numDimensions", 1536) + .append("similarity", "dotProduct") + ) + ), + SearchIndexType.vectorSearch() ) - val resultCreateIndexes = moviesCollection - .createSearchIndexes(listOf(indexOne, indexTwo)) + val resultCreateIndexes = moviesCollection.createSearchIndexes( + listOf(searchIdxMdl, vectorSearchIdxMdl) + ) // :snippet-end: - assertEquals(listOf("myIndex1", "myIndex2"), resultCreateIndexes.toList()) + assertEquals(listOf("searchIdx", "vsIdx"), resultCreateIndexes.toList()) } @Ignore diff --git a/source/examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt b/source/examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt index 238dcc8e..79c3f586 100644 --- a/source/examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt +++ b/source/examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt @@ -1,16 +1,25 @@ -val indexOne = SearchIndexModel( - "myIndex1", +val searchIdxMdl = SearchIndexModel( + "searchIdx", Document("analyzer", "lucene.standard").append( "mappings", Document("dynamic", true) - ) + ), + SearchIndexType.search() ) -val indexTwo = SearchIndexModel( - "myIndex2", - Document("analyzer", "lucene.simple").append( - "mappings", Document("dynamic", true) - ) +val vectorSearchIdxMdl = SearchIndexModel( + "vsIdx", + Document( + "fields", + listOf( + Document("type", "vector") + .append("path", "embeddings") + .append("numDimensions", 1536) + .append("similarity", "dotProduct") + ) + ), + SearchIndexType.vectorSearch() ) -val resultCreateIndexes = moviesCollection - .createSearchIndexes(listOf(indexOne, indexTwo)) +val resultCreateIndexes = moviesCollection.createSearchIndexes( + listOf(searchIdxMdl, vectorSearchIdxMdl) +) diff --git a/source/examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt b/source/examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt index 1266fd74..74b5b7bc 100644 --- a/source/examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt +++ b/source/examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt @@ -1,5 +1,5 @@ -val index = Document( +val searchIdx = Document( "mappings", Document("dynamic", true) ) -val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index) +val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", searchIdx) diff --git a/source/fundamentals/indexes.txt b/source/fundamentals/indexes.txt index 305384c4..179e44a2 100644 --- a/source/fundamentals/indexes.txt +++ b/source/fundamentals/indexes.txt @@ -223,19 +223,23 @@ see :manual:`Multikey Indexes ` in the Server manual. .. _kotlin-search-indexes: -Atlas Search Indexes -~~~~~~~~~~~~~~~~~~~~ +Atlas Search and Vector Search Indexes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can programmatically manage your Atlas Search and Atlas Vector +Search indexes by using the {+driver-short+}. The Atlas Search feature enables you to perform full-text searches on -collections hosted on MongoDB Atlas. The indexes specify how you can -perform full-text searches on specific fields. +collections hosted on MongoDB Atlas. To learn more about MongoDB Atlas +Search, see the :atlas:`Atlas Search Indexes +` documentation. -To learn more about MongoDB Atlas Search, see the -:atlas:`Atlas Search Indexes ` -documentation. +Atlas Vector Search enables you to perform semantic searches on vector +embeddings stored in MongoDB Atlas. To learn more about Atlas Vector Search, see the +:ref:`kotlin-atlas-vector-search` section in the Aggregates Builder guide. -You can call the following methods on a collection to manage your Atlas Search -indexes: +You can call the following methods on a collection to manage your Atlas +Search and Vector Search indexes: - ``createSearchIndex()`` - ``createSearchIndexes()`` @@ -258,14 +262,16 @@ Create a Search Index You can use the `createSearchIndex() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/create-search-index.html>`__ and `createSearchIndexes() <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-mongo-collection/create-search-indexes.html>`__ -methods to create Atlas Search indexes on a collection. +methods to create Atlas Search and Vector Search indexes on a +collection. -The following code example shows how to create a single index: +The following code example shows how to create an Atlas Search index: .. literalinclude:: /examples/generated/SearchIndexesTest.snippet.single-search-index-create.kt :language: kotlin -The following code example shows how to create multiple indexes: +The following code example shows how to create Search and +Vector Search indexes in one call: .. literalinclude:: /examples/generated/SearchIndexesTest.snippet.multi-search-index-create.kt :language: kotlin diff --git a/source/whats-new.txt b/source/whats-new.txt index 523226ad..c0b3c0f9 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -12,6 +12,7 @@ What's New Learn what's new in: +* :ref:`Version 5.2 ` * :ref:`Version 5.1.3 ` * :ref:`Version 5.1.2 ` * :ref:`Version 5.1.1 ` @@ -20,6 +21,19 @@ Learn what's new in: * :ref:`Version 4.11 ` * :ref:`Version 4.10 ` +.. _kotlin-coroutine-version-5.2: + +What's New in 5.2 +----------------- + +New features of the 4.11 driver release include: + +.. sharedinclude:: dbx/jvm/v5.2-wn-items.rst + + .. replacement:: avs-index-link + + :ref:`kotlin-search-indexes` in the Indexes guide + .. _kotlin-coroutine-version-5.1.3: What's New in 5.1.3 From 442df9459425e23a32ee4e39c6fb7e00072e3990 Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Fri, 16 Aug 2024 10:25:36 -0500 Subject: [PATCH 18/20] Add files via upload --- build.sh | 8 ++++++++ netlify.toml | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 build.sh create mode 100644 netlify.toml diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..b62b6772 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +# ensures that we always use the latest version of the script +if [ -f build-site.sh ]; then + rm build-site.sh +fi + + +curl https://raw.githubusercontent.com/mongodb/docs-worker-pool/netlify-poc/scripts/build-site.sh -o build-site.sh +sh build-site.sh \ No newline at end of file diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000..2d0a3b98 --- /dev/null +++ b/netlify.toml @@ -0,0 +1,9 @@ +[[integrations]] +name = "snooty-cache-plugin" + +# Production context: all deploys from the Production branch +# set in your site’s Branches settings in the UI will inherit +# these settings. +[build] +publish = "snooty/public" +command = ". ./build.sh" From 580a5d259b1ab699bb9d7dcf75287a1ddef8ba14 Mon Sep 17 00:00:00 2001 From: rustagir Date: Tue, 20 Aug 2024 14:14:44 -0400 Subject: [PATCH 19/20] ignore search indexes test --- examples/src/test/kotlin/SearchIndexesTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/src/test/kotlin/SearchIndexesTest.kt b/examples/src/test/kotlin/SearchIndexesTest.kt index ea6d09c4..47b8b44f 100644 --- a/examples/src/test/kotlin/SearchIndexesTest.kt +++ b/examples/src/test/kotlin/SearchIndexesTest.kt @@ -54,7 +54,6 @@ class SearchIndexesTest { } @Ignore - @Test fun multipleSearchIndexTest() = runBlocking { // :snippet-start: multi-search-index-create val searchIdxMdl = SearchIndexModel( From 2d7c437715654c85858019f817b4557daacea032 Mon Sep 17 00:00:00 2001 From: Stephanie Aurelio Date: Mon, 26 Aug 2024 13:04:18 -0700 Subject: [PATCH 20/20] update references --- source/fundamentals/transactions.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/fundamentals/transactions.txt b/source/fundamentals/transactions.txt index be271c8a..0656b5cd 100644 --- a/source/fundamentals/transactions.txt +++ b/source/fundamentals/transactions.txt @@ -38,15 +38,15 @@ guarantees that the data involved in your transaction operations remains consistent, even if the operations encounter unexpected errors. When using the {+driver-short+}, you can create a new session from a -``Client`` instance as a ``ClientSession``. We recommend that you reuse +``MongoClient`` instance as a ``ClientSession``. We recommend that you reuse your client for multiple sessions and transactions instead of instantiating a new client each time. .. warning:: - Use a ``Session`` only with the ``Client`` (or associated - ``Database`` or ``Collection``) that created it. Using a - ``Session`` with a different ``Client`` results in operation + Use a ``ClientSession`` only with the ``MongoClient`` (or associated + ``MongoDatabase`` or ``MongoCollection``) that created it. Using a + ``ClientSession`` with a different ``MongoClient`` results in operation errors. Methods @@ -81,7 +81,7 @@ following methods: error if there is no active transaction for the session or if the transaction was ended. -A ``Session`` also has methods to retrieve session properties and modify +A ``ClientSession`` also has methods to retrieve session properties and modify mutable session properties. View the `API documentation <{+api+}/apidocs/mongodb-driver-kotlin-coroutine/mongodb-driver-kotlin-coroutine/com.mongodb.kotlin.client.coroutine/-client-session/index.html>`__ to learn more about these methods.