Skip to content

Commit 89c98a3

Browse files
authored
Merge pull request #20 from mongodben/DOCSP-29239
(DOCSP-29239): Kotlin Stable API page
2 parents 6f0ea6c + b56eae0 commit 89c98a3

File tree

6 files changed

+89
-23
lines changed

6 files changed

+89
-23
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
import com.mongodb.ConnectionString
3+
import com.mongodb.MongoClientSettings
4+
import com.mongodb.ServerApi
5+
import com.mongodb.ServerApiVersion
6+
import com.mongodb.kotlin.client.coroutine.MongoClient
7+
import io.github.cdimascio.dotenv.dotenv
8+
import org.junit.jupiter.api.Test
9+
import org.junit.jupiter.api.TestInstance
10+
import kotlin.test.assertEquals
11+
12+
13+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
14+
internal class StableApiTest {
15+
16+
companion object {
17+
val dotenv = dotenv()
18+
val CONNECTION_URI_PLACEHOLDER = dotenv["MONGODB_CONNECTION_URI"]
19+
}
20+
@Test
21+
fun connectToStableApiTest() {
22+
// :snippet-start: connect-to-stable-api
23+
val serverApi = ServerApi.builder()
24+
.version(ServerApiVersion.V1)
25+
.build()
26+
27+
// Replace the uri string placeholder with your MongoDB deployment's connection string
28+
val uri = CONNECTION_URI_PLACEHOLDER
29+
30+
val settings = MongoClientSettings.builder()
31+
.applyConnectionString(ConnectionString(uri))
32+
.serverApi(serverApi)
33+
.build()
34+
35+
val client = MongoClient.create(settings)
36+
// :snippet-end:
37+
client.close()
38+
assert(settings.serverApi?.version == ServerApiVersion.V1)
39+
}
40+
41+
@Test
42+
fun stableApiSettingsTest() {
43+
// :snippet-start: stable-api-settings
44+
val serverApi = ServerApi.builder()
45+
.version(ServerApiVersion.V1)
46+
.strict(true)
47+
.deprecationErrors(true)
48+
.build()
49+
// :snippet-end:
50+
assert(serverApi.version == ServerApiVersion.V1)
51+
assertEquals(true, serverApi.strict.get())
52+
assertEquals(true, serverApi.deprecationErrors.get())
53+
}
54+
55+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
val serverApi = ServerApi.builder()
2+
.version(ServerApiVersion.V1)
3+
.build()
4+
5+
// Replace the uri string placeholder with your MongoDB deployment's connection string
6+
val uri = CONNECTION_URI_PLACEHOLDER
7+
8+
val settings = MongoClientSettings.builder()
9+
.applyConnectionString(ConnectionString(uri))
10+
.serverApi(serverApi)
11+
.build()
12+
13+
val client = MongoClient.create(settings)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
val serverApi = ServerApi.builder()
2+
.version(ServerApiVersion.V1)
3+
.strict(true)
4+
.deprecationErrors(true)
5+
.build()

source/fundamentals.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Fundamentals
99
:maxdepth: 1
1010

1111
/fundamentals/connection
12+
/fundamentals/stable-api
1213
/fundamentals/databases-collections
1314
/fundamentals/data-formats
1415
/fundamentals/crud
@@ -21,7 +22,6 @@ Fundamentals
2122
.. TODO : add back in after MVP
2223
.. /fundamentals/auth
2324
.. /fundamentals/enterprise-auth
24-
.. /fundamentals/stable-api
2525
.. /fundamentals/collations
2626
.. /fundamentals/gridfs
2727
.. /fundamentals/csfle

source/fundamentals/stable-api.txt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,11 @@ following operations:
6969
- Construct a ``MongoClientSettings`` instance using the
7070
``MongoClientSettings.Builder`` class.
7171
- Specify a server to connect to using a ``ServerAddress`` instance.
72-
- Instantiate a ``MongoClient`` using the ``MongoClients.create()`` method
72+
- Instantiate a ``MongoClient`` using the ``MongoClient.create()`` method
7373
and pass your ``MongoClientSettings`` instance as a parameter.
7474

75-
.. literalinclude:: /includes/fundamentals/code-snippets/StableApiExample.java
76-
:start-after: start serverAPIVersion
77-
:end-before: end serverAPIVersion
78-
:language: java
79-
:dedent:
75+
.. literalinclude:: /examples/generated/StableApiTest.snippet.connect-to-stable-api.kt
76+
:language: kotlin
8077

8178
.. warning::
8279

@@ -95,14 +92,14 @@ following operations:
9592
For more information on the methods and classes referenced in this
9693
section, see the following API Documentation:
9794

98-
- `ServerApi <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ServerApi.html>`__
99-
- `ServerApi.Builder <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ServerApi.Builder.html>`__
100-
- `ServerApiVersion <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ServerApiVersion.html>`__
101-
- `ServerAddress <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ServerAddress.html>`__
102-
- `MongoClientSettings <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.html>`__
103-
- `MongoClientSettings.Builder <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__
104-
- `MongoClients.create() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoClients.html#create(com.mongodb.MongoClientSettings)>`__
105-
- `MongoClient <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoClient.html>`__
95+
- `ServerApi <TODO:(DOCSP-29169)>`__
96+
- `ServerApi.Builder <TODO:(DOCSP-29169)>`__
97+
- `ServerApiVersion <TODO:(DOCSP-29169)>`__
98+
- `ServerAddress <TODO:(DOCSP-29169)>`__
99+
- `MongoClientSettings <TODO:(DOCSP-29169)>`__
100+
- `MongoClientSettings.Builder <TODO:(DOCSP-29169)>`__
101+
- `MongoClient.create() <TODO:(DOCSP-29169)>`__
102+
- `MongoClient <TODO:(DOCSP-29169)>`__
106103

107104
.. _versioned-api-options:
108105
.. _stable-api-options:
@@ -134,15 +131,12 @@ described in the following table.
134131
The following example shows how you can set the two options on an instance
135132
of ``ServerApi`` by chaining methods on the ``ServerApi.Builder``:
136133

137-
.. literalinclude:: /includes/fundamentals/code-snippets/StableApiExample.java
138-
:start-after: start apiVersionOptions
139-
:end-before: end apiVersionOptions
140-
:language: java
141-
:dedent:
134+
.. literalinclude:: /examples/generated/StableApiTest.snippet.stable-api-settings.kt
135+
:language: kotlin
142136

143137
For more information on the options in this section, see the following
144138
API Documentation:
145139

146-
- `strict() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ServerApi.Builder.html#strict(boolean)>`__
147-
- `deprecationErrors() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/ServerApi.Builder.html#>`__
140+
- `strict() <TODO:(DOCSP-29169)>`__
141+
- `deprecationErrors() <TODO:(DOCSP-29169)>`__
148142

source/includes/fundamentals-sections.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Fundamentals section:
1212
- :doc:`Monitor Driver Events </fundamentals/monitoring>`
1313

1414
.. TODO : add back in after MVP
15-
1615
.. - :doc:`Authenticate with MongoDB </fundamentals/auth>`
1716
.. - :doc:`Transform your Data </fundamentals/aggregation>`
1817
.. - :doc:`Sort Using Collations </fundamentals/collations>`

0 commit comments

Comments
 (0)