Skip to content

Commit 4628990

Browse files
authored
Merge pull request #122 from mcmorisi/DOCSP-45181-stable-api
DOCSP-45181: Stable API
2 parents 9f42b50 + 448ee7d commit 4628990

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

source/connect.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ Connect to MongoDB
2222
:titlesonly:
2323
:maxdepth: 1
2424

25-
/connect/mongoclient
25+
/connect/mongoclient
26+
/connect/stable-api

source/connect/stable-api.txt

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.. _ruby-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. Using the {+stable-api+} ensures consistent responses
32+
from the server and provides long-term API stability for your application.
33+
34+
The following sections describe how you can enable and customize the {+stable-api+} for
35+
your MongoDB client. For more information about the {+stable-api+}, including a list of
36+
the commands it supports, see :manual:`Stable API </reference/stable-api/>` in the
37+
{+mdb-server+} manual.
38+
39+
Enable the {+stable-api+}
40+
-------------------------
41+
42+
To enable the {+stable-api+}, pass a hash that specifies the {+stable-api+} version to the optional
43+
``server_api`` parameter when you create a ``Mongo::Client`` instance.
44+
45+
The following code example shows how to specify {+stable-api+} version 1:
46+
47+
.. code-block:: ruby
48+
49+
client = Mongo::Client.new(uri, server_api: { version: '1' })
50+
51+
Once you create a ``Client`` instance with
52+
a specified API version, all commands that you run with the client use the specified
53+
version. If you must run commands using more than one version of the
54+
{+stable-api+}, create a new ``Client``.
55+
56+
Configure the {+stable-api+}
57+
----------------------------
58+
59+
The following table describes {+stable-api+} options that you can set by specifying
60+
them in the ``server_api`` hash. You can use these options to customize the behavior of the
61+
{+stable-api+}.
62+
63+
.. list-table::
64+
:header-rows: 1
65+
:stub-columns: 1
66+
:widths: 25,75
67+
68+
* - Option Name
69+
- Description
70+
71+
* - strict
72+
- | **Optional**. When ``true``, if you call a command that isn't part of
73+
the declared API version, the driver raises an exception.
74+
|
75+
| Default: **false**
76+
77+
* - deprecation_errors
78+
- | **Optional**. When ``true``, if you call a command that is deprecated in the
79+
declared API version, the driver raises an exception.
80+
|
81+
| Default: **false**
82+
83+
The following code example shows how you can set the two options on a ``ServerApi`` instance:
84+
85+
.. code-block:: ruby
86+
87+
client = Mongo::Client.new(uri,
88+
server_api: { version: '1', strict: true, deprecation_errors: true })
89+
90+
Troubleshooting
91+
---------------
92+
93+
The following sections describe common issues you might encounter when using the {+stable-api+}.
94+
95+
Unrecognized field 'apiVersion' on server
96+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97+
98+
The {+driver-short+} raises this exception if you specify an API version and connect to a
99+
MongoDB server that doesn't support the {+stable-api+}. Ensure you're connecting to a
100+
deployment running {+mdb-server+} v5.0 or later.
101+
102+
Provided apiStrict:true, but the command count is not in API Version
103+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104+
105+
The {+driver-short+} raises this exception if your ``Client`` runs an operation that
106+
isn't in the {+stable-api+} version you specified. To avoid this error, use an alternative
107+
operation supported by the specified {+stable-api+} version, or set the ``strict``
108+
option to ``false`` when constructing your ``ServerApi`` object.
109+
110+
API Documentation
111+
-----------------
112+
113+
For more information about using the {+stable-api+} with the {+driver-short+}, see the
114+
following API documentation:
115+
116+
- `Mongo::Client <{+api-root+}/Mongo/Client.html>`__

0 commit comments

Comments
 (0)