Skip to content

Commit c4c504c

Browse files
committed
first draft
1 parent bdd0fca commit c4c504c

File tree

4 files changed

+142
-2
lines changed

4 files changed

+142
-2
lines changed

snooty.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ php-library = "MongoDB PHP Library"
2727

2828
php-library = "MongoDB PHP Library"
2929
driver-short = "PHP library"
30+
extension-short = "PHP extension"
3031
mdb-server = "MongoDB Server"
31-
driver-short = "PHP library"
3232
api = "https://www.mongodb.com/docs/php-library/current/reference"

source/connect/stable-api.txt

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
.. _php-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 ``MongoDB\Driver\ServerApi`` object and pass the {+stable-api+}
47+
version you want to use. Currently, the driver supports only version 1.
48+
#. Construct a ``MongoDB\Client`` object. For the ``driverOptions`` parameter, pass an
49+
array that contains the ``serverApi`` connection option. Set this option to the
50+
``MongoDB\Driver\ServerApi`` object you created in the previous step.
51+
52+
The following code example shows how to specify {+stable-api+} version 1:
53+
54+
.. literalinclude:: /includes/connect/stable-api.php
55+
:language: php
56+
:copyable: true
57+
:start-after: // start-specify-v1
58+
:end-before: // end-specify-v1
59+
:emphasize-lines: 5-7
60+
61+
.. note::
62+
63+
After you create a ``MongoDB\Client`` instance with
64+
a specified API version, all commands you run with the client use the specified
65+
version. If you need to run commands using more than one version of the
66+
{+stable-api+}, create a new ``MongoDB\Client`` instance.
67+
68+
.. _stable-api-options:
69+
70+
Configure the {+stable-api+}
71+
------------------------
72+
73+
The following table describes the parameters of the ``MongoDB\Driver\ServerApi`` constructor.
74+
You can use these parameters to customize the behavior of the {+stable-api+}.
75+
76+
.. list-table::
77+
:header-rows: 1
78+
:stub-columns: 1
79+
:widths: 25,75
80+
81+
* - Option Name
82+
- Description
83+
84+
* - strict
85+
- | **Optional**. When ``true``, if you call a command that isn't part of
86+
the declared API version, the library raises an exception.
87+
|
88+
| Default: ``false``
89+
90+
* - deprecationErrors
91+
- | **Optional**. When ``true``, if you call a command that is deprecated in the
92+
declared API version, the library raises an exception.
93+
|
94+
| Default: ``false``
95+
96+
The following code example shows how you can use these parameters when constructing a
97+
``MongoDB\Driver\ServerApi`` object:
98+
99+
.. literalinclude:: /includes/connect/stable-api.php
100+
:language: php
101+
:copyable: true
102+
:start-after: // start-stable-api-options
103+
:end-before: // end-stable-api-options
104+
:emphasize-lines: 5-7
105+
106+
API Documentation
107+
-----------------
108+
109+
For more information about the ``MongoDB\Client`` class, see the following {+driver-short+}
110+
API documentation:
111+
112+
- :ref:`MongoDB\Client <php-api-mongodbclient>`
113+
114+
For more information about the ``MongoDB\Driver\ServerApi`` class, see the following
115+
{+extension-short+} API documentation:
116+
117+
- `MongoDB\\Driver\\ServerApi <https://www.php.net/manual/en/class.mongodb-driver-serverapi.php>`__

source/connect/tls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,4 @@ API Documentation
265265
To learn more about configuring TLS for the {+driver-short+},
266266
see the following API documentation:
267267

268-
- :ref:`MongoDB\Client <php-mongodb-client>`
268+
- :ref:`MongoDB\Client <php-api-mongodbclient>`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// start-specify-v1
2+
<?php
3+
4+
$uri = "mongodb://<hostname>:<port>";
5+
6+
$client = new MongoDB\Client($uri, [], [
7+
'serverApi' => new MongoDB\Driver\ServerApi('1')
8+
]);
9+
10+
?>
11+
// end-specify-v1
12+
13+
// start-stable-api-options
14+
<?php
15+
16+
$uri = "mongodb://<hostname>:<port>";
17+
18+
$client = new MongoDB\Client($uri, [], [
19+
'serverApi' => new MongoDB\Driver\ServerApi('1', true, true)
20+
]);
21+
22+
?>
23+
// end-stable-api-options

0 commit comments

Comments
 (0)