Skip to content

Commit 5a83299

Browse files
authored
DOCSP-41125 Stable API (#18)
* DOCSP-41125 Stable API * refs and reminaing * connect page * snooty * toc * troubleshooting * broken links * remaining comments * links * revert snooty * spacing * remove unnecessary quick-reference * remove quick-ref from landing
1 parent b122b68 commit 5a83299

File tree

6 files changed

+187
-17
lines changed

6 files changed

+187
-17
lines changed

source/connect.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ Connect to MongoDB
1818
:description: Learn how to use the Kotlin Sync driver to connect to MongoDB.
1919
:keywords: client, ssl, tls, localhost
2020

21-
.. .. toctree::
22-
.. :titlesonly:
23-
.. :maxdepth: 1
21+
.. toctree::
22+
:titlesonly:
23+
:maxdepth: 1
24+
25+
/connect/stable-api
2426
..
2527
.. /connect/mongoclient
2628
.. /connect/connection-targets
2729
.. /connect/connection-options
2830
.. /connect/tls
2931
.. /connect/network-compression
3032
.. /connect/server-selection
31-
.. /connect/stable-api
3233
.. /connect/csot
3334

3435
Overview

source/connect/stable-api.txt

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
.. _kotlin-sync-stable-api:
2+
3+
==============
4+
{+stable-api+}
5+
==============
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: compatible, backwards, upgrade
19+
20+
.. note::
21+
22+
The {+stable-api+} feature requires {+mdb-server+} 5.0 or later.
23+
24+
Overview
25+
--------
26+
27+
In this guide, you can learn how to specify **{+stable-api+}** compatibility when
28+
connecting to a MongoDB deployment.
29+
30+
The {+stable-api+} feature forces the server to run operations with behaviors compatible
31+
with the API version you specify. When you update either your driver or server,
32+
the API version changes, which can change the way these operations behave.
33+
Using the {+stable-api+} ensures consistent responses from the server and
34+
provides long-term API stability for your application.
35+
36+
The following sections describe how you can enable and customize {+stable-api+} for
37+
your MongoDB client. For more information about the {+stable-api+}, including a list of
38+
the commands it supports, see :manual:`Stable API </reference/stable-api/>` in the
39+
{+mdb-server+} manual.
40+
41+
Enable the {+stable-api+}
42+
-------------------------
43+
44+
To enable the {+stable-api+}, perform the following steps:
45+
46+
1. Construct a ``ServerApi`` object and specify a {+stable-api+} version. You must use
47+
a {+stable-api+} version defined in the ``ServerApiVersion`` enum.
48+
#. Construct a ``MongoClientSettings`` object using the ``MongoClientSettings.Builder`` class.
49+
#. Instantiate a ``MongoClient`` using the ``MongoClient.create()`` method and
50+
pass your ``MongoClientSettings`` instance as a parameter.
51+
52+
The following code example shows how to specify {+stable-api+} version 1:
53+
54+
.. literalinclude:: /includes/connect/stable-api.kt
55+
:start-after: start-enable-stable-api
56+
:end-before: end-enable-stable-api
57+
:language: kotlin
58+
:copyable:
59+
:dedent:
60+
61+
Once you create a ``MongoClient`` instance with
62+
a specified API version, all commands you run with the client use the specified
63+
version. If you must run commands using more than one version of the
64+
{+stable-api+}, create a new ``MongoClient``.
65+
66+
.. _stable-api-options:
67+
68+
Configure the {+stable-api+}
69+
----------------------------
70+
71+
The following table describes the parameters of the ``ServerApi`` class. You can use these
72+
parameters to customize the behavior of the {+stable-api+}.
73+
74+
.. list-table::
75+
:header-rows: 1
76+
:stub-columns: 1
77+
:widths: 25,75
78+
79+
* - Option Name
80+
- Description
81+
82+
* - strict
83+
- | **Optional**. When ``True``, if you call a command that isn't part of
84+
the declared API version, the driver raises an exception.
85+
|
86+
| Default: **False**
87+
88+
* - deprecationErrors
89+
- | **Optional**. When ``True``, if you call a command that is deprecated in the
90+
declared API version, the driver raises an exception.
91+
|
92+
| Default: **False**
93+
94+
The following code example shows how you can set the two options on an instance of ``ServerApi``
95+
by chaining methods on the ``ServerApi.Builder``:
96+
97+
.. literalinclude:: /includes/connect/stable-api-options.kt
98+
:start-after: start-stable-api-options
99+
:end-before: end-stable-api-options
100+
:language: kotlin
101+
:copyable:
102+
:dedent:
103+
104+
Troubleshooting
105+
---------------
106+
107+
Unrecognized field 'apiVersion' on server
108+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109+
110+
The {+driver-short+} raises this exception if you specify an API version and connect to a
111+
MongoDB server that doesn't support the {+stable-api+}. Ensure you're connecting to a
112+
deployment running {+mdb-server+} v5.0 or later.
113+
114+
Provided apiStrict:true, but the command count is not in API Version
115+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116+
117+
The {+driver-short+} raises this exception if your ``MongoClient`` runs an operation that
118+
isn't in the {+stable-api+} version you specified. To avoid this error, use an alternative
119+
operation supported by the specified {+stable-api+} version, or set the ``strict``
120+
option to ``False`` when constructing your ``ServerApi`` object.
121+
122+
API Documentation
123+
-----------------
124+
125+
For more information about using the {+stable-api+} with {+driver-short+}, see the
126+
following API documentation:
127+
128+
- `ServerApi <{+core-api+}com/mongodb/ServerApi.html>`__
129+
- `ServerApi.Builder <{+core-api+}com/mongodb/ServerApi.Builder.html>`__
130+
- `ServerApiVersion <{+core-api+}com/mongodb/ServerApiVersion.html>`__
131+
- `ServerAddress <{+core-api+}com/mongodb/ServerAddress.html>`__
132+
- `MongoClientSettings <{+core-api+}com/mongodb/MongoClientSettings.html>`__
133+
- `MongoClientSettings.Builder <{+core-api+}com/mongodb/MongoClientSettings.Builder.html>`__
134+
- `MongoClient <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
135+
- `MongoClient.create() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/-factory/create.html>`__
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import com.mongodb.ConnectionString
2+
import com.mongodb.MongoClientSettings
3+
import com.mongodb.client.model.*
4+
import com.mongodb.kotlin.client.*
5+
import org.bson.Document
6+
7+
fun main() {
8+
9+
// start-stable-api-options
10+
val serverApi = ServerApi.builder()
11+
.version(ServerApiVersion.V1)
12+
.strict(true)
13+
.deprecationErrors(true)
14+
.build()
15+
// end-stable-api-options
16+
}

source/includes/connect/stable-api.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import com.mongodb.ConnectionString
2+
import com.mongodb.MongoClientSettings
3+
import com.mongodb.client.model.*
4+
import com.mongodb.kotlin.client.*
5+
import org.bson.Document
6+
7+
fun main() {
8+
9+
// start-enable-stable-api
10+
val serverApi = ServerApi.builder()
11+
.version(ServerApiVersion.V1)
12+
.build()
13+
14+
// Replace the uri string placeholder with your MongoDB deployment's connection string
15+
val uri = "<connection string>"
16+
17+
val settings = MongoClientSettings.builder()
18+
.applyConnectionString(ConnectionString(uri))
19+
.serverApi(serverApi)
20+
.build()
21+
22+
val client = MongoClient.create(settings)
23+
// end-enable-stable-api
24+
25+
val serverApi = ServerApi.builder()
26+
.version(ServerApiVersion.V1)
27+
.strict(true)
28+
.deprecationErrors(true)
29+
.build()
30+
31+
}

source/index.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ What's New
6262
For a list of new features and changes in each version, see the :ref:`What's New <kotlin-sync-whats-new>`
6363
section.
6464

65-
Quick Reference
66-
---------------
67-
68-
See driver syntax examples for common MongoDB commands in the
69-
:ref:`Quick Reference <kotlin-sync-quick-reference>` section.
70-
7165
Write Data to MongoDB
7266
---------------------
7367

source/quick-reference.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)