-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-45181: Stable API #122
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
Merged
mcmorisi
merged 3 commits into
mongodb:standardization
from
mcmorisi:DOCSP-45181-stable-api
Jan 10, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ Connect to MongoDB | |
:titlesonly: | ||
:maxdepth: 1 | ||
|
||
/connect/mongoclient | ||
/connect/mongoclient | ||
/connect/stable-api |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
.. _ruby-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. 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 the {+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+}, pass a hash that specifies the {+stable-api+} version to the optional | ||
``server_api`` parameter when you create a ``Mongo::Client`` instance. | ||
|
||
The following code example shows how to specify {+stable-api+} version 1: | ||
|
||
.. code-block:: ruby | ||
|
||
client = Mongo::Client.new(uri, server_api: { version: '1' }) | ||
|
||
Once you create a ``Client`` instance with | ||
a specified API version, all commands that you run with the client use the specified | ||
version. If you must run commands using more than one version of the | ||
{+stable-api+}, create a new ``Client``. | ||
|
||
Configure the {+stable-api+} | ||
---------------------------- | ||
|
||
The following table describes {+stable-api+} options that you can set by specifying | ||
them in the ``server_api`` hash. You can use these options 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 | ||
the declared API version, the driver raises an exception. | ||
| | ||
| Default: **false** | ||
|
||
* - deprecation_errors | ||
- | **Optional**. When ``true``, if you call a command that is deprecated in the | ||
declared API version, the driver raises an exception. | ||
| | ||
| Default: **false** | ||
|
||
The following code example shows how you can set the two options on a ``ServerApi`` instance: | ||
|
||
.. code-block:: ruby | ||
|
||
client = Mongo::Client.new(uri, | ||
server_api: { version: '1', strict: true, deprecation_errors: true }) | ||
|
||
Troubleshooting | ||
--------------- | ||
|
||
The following sections describe common issues you might encounter when using the {+stable-api+}. | ||
|
||
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 | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
The {+driver-short+} raises this exception if your ``Client`` 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: | ||
|
||
- `Mongo::Client <{+api-root+}/Mongo/Client.html>`__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.