-
Notifications
You must be signed in to change notification settings - Fork 17
DOCSP-42298: Stable API #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,134 @@ | ||||||||||
.. _java-rs-stable-api: | ||||||||||
|
||||||||||
========== | ||||||||||
{+stable-api+} | ||||||||||
========== | ||||||||||
|
||||||||||
.. contents:: On this page | ||||||||||
:local: | ||||||||||
:backlinks: none | ||||||||||
:depth: 2 | ||||||||||
:class: singlecol | ||||||||||
|
||||||||||
.. facet:: | ||||||||||
:name: genre | ||||||||||
:values: reference | ||||||||||
|
||||||||||
.. meta:: | ||||||||||
:keywords: compatible, backwards, upgrade | ||||||||||
|
||||||||||
.. note:: | ||||||||||
|
||||||||||
The {+stable-api+} feature requires {+mdb-server+} 5.0 or later. | ||||||||||
|
||||||||||
Overview | ||||||||||
-------- | ||||||||||
|
||||||||||
In this guide, you can learn how to specify **{+stable-api+}** compatibility when | ||||||||||
connecting to a MongoDB deployment. | ||||||||||
|
||||||||||
The {+stable-api+} feature forces the server to run operations with behaviors compatible | ||||||||||
with the API version you specify. When you update either your driver or server, | ||||||||||
the API version changes, which can change the way these operations behave. | ||||||||||
Using the {+stable-api+} ensures consistent responses from the server and | ||||||||||
provides long-term API stability for your application. | ||||||||||
|
||||||||||
The following sections describe how you can enable and customize {+stable-api+} for | ||||||||||
your MongoDB client. For more information about the {+stable-api+}, including a list of | ||||||||||
the commands it supports, see :manual:`Stable API </reference/stable-api/>` in the | ||||||||||
{+mdb-server+} manual. | ||||||||||
|
||||||||||
Enable the {+stable-api+} | ||||||||||
------------------------- | ||||||||||
|
||||||||||
To enable the {+stable-api+}, perform the following steps: | ||||||||||
|
||||||||||
1. Construct a ``ServerApi`` object and specify a {+stable-api+} version. You must use | ||||||||||
a {+stable-api+} version defined in the ``ServerApiVersion`` enum. | ||||||||||
#. Construct a ``MongoClientSettings`` object using the ``MongoClientSettings.Builder`` class. | ||||||||||
#. Instantiate a ``MongoClient`` using the ``MongoClients.create()`` method and | ||||||||||
pass your ``MongoClientSettings`` instance as a parameter. | ||||||||||
|
||||||||||
The following code example shows how to specify {+stable-api+} version 1: | ||||||||||
|
||||||||||
.. literalinclude:: /includes/connect/stable-api.java | ||||||||||
:start-after: start-enable-stable-api | ||||||||||
:end-before: end-enable-stable-api | ||||||||||
:language: java | ||||||||||
:copyable: | ||||||||||
:dedent: | ||||||||||
|
||||||||||
Once you create a ``MongoClient`` instance with | ||||||||||
a specified API version, all commands you run with the client use the specified | ||||||||||
version. If you must run commands using more than one version of the | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently there is only one version of the Stable API: V1. Consider changing this to refer to one of the other properties of the ServerApi class, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we expect another version to release? It could benefit us to cover our bases in advance of future versions. I can also tweak the last highlighted sentence to the following more general version:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have heard nothing about a new version coming out. |
||||||||||
{+stable-api+}, create a new ``MongoClient``. | ||||||||||
|
||||||||||
.. _java-rs-stable-api-options: | ||||||||||
|
||||||||||
Configure the {+stable-api+} | ||||||||||
---------------------------- | ||||||||||
|
||||||||||
The following table describes chainable methods of the ``ServerApi.Builder`` class that | ||||||||||
you can use to customize the behavior of the {+stable-api+}. | ||||||||||
|
||||||||||
.. list-table:: | ||||||||||
:header-rows: 1 | ||||||||||
:stub-columns: 1 | ||||||||||
:widths: 25,75 | ||||||||||
|
||||||||||
* - Option Name | ||||||||||
- Description | ||||||||||
|
||||||||||
* - ``strict()`` | ||||||||||
- | **Optional**. When ``True``, if you call a command that isn't part of | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
the declared API version, the driver raises an exception. | ||||||||||
| | ||||||||||
| Default: **False** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
* - ``deprecationErrors()`` | ||||||||||
- | **Optional**. When ``True``, if you call a command that is deprecated in the | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
declared API version, the driver raises an exception. | ||||||||||
| | ||||||||||
| Default: **False** | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
The following code example shows how you can set configurations on an instance of ``ServerApi`` | ||||||||||
by chaining methods on the ``ServerApi.Builder``: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S:
Suggested change
|
||||||||||
|
||||||||||
.. literalinclude:: /includes/connect/stable-api.java | ||||||||||
:start-after: start-stable-api-options | ||||||||||
:end-before: end-stable-api-options | ||||||||||
:language: java | ||||||||||
:copyable: | ||||||||||
:dedent: | ||||||||||
|
||||||||||
Troubleshooting | ||||||||||
--------------- | ||||||||||
|
||||||||||
Unrecognized field 'apiVersion' on server | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
|
||||||||||
The {+driver-short+} raises this exception if you specify an API version and connect to a | ||||||||||
MongoDB server that doesn't support the {+stable-api+}. Ensure you're connecting to a | ||||||||||
deployment running {+mdb-server+} v5.0 or later. | ||||||||||
|
||||||||||
Provided apiStrict:true, but the command count is not in API Version | ||||||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a general operation instead of directly applying to
Suggested change
|
||||||||||
|
||||||||||
The {+driver-short+} raises this exception if your ``MongoClient`` runs an operation that | ||||||||||
isn't in the {+stable-api+} version you specified. To avoid this error, use an alternative | ||||||||||
operation supported by the specified {+stable-api+} version, or set the ``strict`` | ||||||||||
option to ``False`` when constructing your ``ServerApi`` object. | ||||||||||
|
||||||||||
API Documentation | ||||||||||
----------------- | ||||||||||
|
||||||||||
For more information about using the {+stable-api+} with the {+driver-short+}, see the | ||||||||||
following API documentation: | ||||||||||
|
||||||||||
- `ServerApi <{+api+}/mongodb-driver-core/com/mongodb/ServerApi.html>`__ | ||||||||||
- `ServerApi.Builder <{+api+}/mongodb-driver-core/com/mongodb/ServerApi.Builder.html>`__ | ||||||||||
- `ServerApiVersion <{+api+}/mongodb-driver-core/com/mongodb/ServerApiVersion.html>`__ | ||||||||||
- `ServerAddress <{+api+}/mongodb-driver-core/com/mongodb/ServerAddress.html>`__ | ||||||||||
- `MongoClientSettings <{+api+}/mongodb-driver-core/com/mongodb/MongoClientSettings.html>`__ | ||||||||||
- `MongoClientSettings.Builder <{+api+}/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__ | ||||||||||
- `MongoClients <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClients.html>`__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.example; | ||
|
||
import com.mongodb.ConnectionString; | ||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.ServerApi; | ||
import com.mongodb.ServerApiVersion; | ||
|
||
import com.mongodb.reactivestreams.client.*; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
// start-enable-stable-api | ||
ServerApi serverApi = ServerApi.builder() | ||
.version(ServerApiVersion.V1) | ||
.build(); | ||
|
||
// Replace the placeholder with your Atlas connection string | ||
String uri = "<connection string URI>"; | ||
|
||
MongoClientSettings settings = MongoClientSettings.builder() | ||
.applyConnectionString(new ConnectionString(uri)) | ||
.serverApi(serverApi) | ||
.build(); | ||
|
||
try (MongoClient mongoClient = MongoClients.create(settings)) { | ||
// Perform client operations here | ||
} | ||
// end-enable-stable-api | ||
|
||
// start-stable-api-options | ||
ServerApi serverApi = ServerApi.builder() | ||
.version(ServerApiVersion.V1) | ||
.strict(true) | ||
.deprecationErrors(true) | ||
.build(); | ||
// end-stable-api-options | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not accurate. Was this text copied from somewhere else?
https://www.mongodb.com/docs/manual/reference/stable-api/ looks accurate to me, so we should either link to it or crib from it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description was taken from the same page from a different driver, yes. Can take this back to the team to investigate whether there's a larger-scope misunderstanding here.
In the meantime, can remove the sentence you called out, as I believe the remaining copy adequately explains the feature (plus we have the link to the server manual).