-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41962 - Stable API #117
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
mongoKart
merged 10 commits into
mongodb:php-standardization
from
mongoKart:docsp-41962-stable-api
Sep 25, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4c504c
first draft
mongoKart a1b3322
add source constant
mongoKart fde84d8
feedback
mongoKart 1101bde
phpclass directive
mongoKart 03f667a
autobuilder
mongoKart dd323f7
feedback
mongoKart 5c80f10
formatting
mongoKart ef8dcb3
Apply suggestions from code review
mongoKart 4338b10
feedback
mongoKart 4434310
Merge branch 'php-standardization' into docsp-41962-stable-api
mongoKart 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
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,119 @@ | ||
.. _php-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 library or server version, | ||
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 ``MongoDB\Driver\ServerApi`` object and pass the {+stable-api+} | ||
version you want to use. Currently, the library supports only version 1. | ||
#. Construct a ``MongoDB\Client`` object. For the ``driverOptions`` parameter, pass an | ||
array that contains the ``serverApi`` option. Set this option to the | ||
``MongoDB\Driver\ServerApi`` object you created in the previous step. | ||
|
||
The following code example shows how to specify {+stable-api+} version 1: | ||
|
||
.. literalinclude:: /includes/connect/stable-api.php | ||
:language: php | ||
:copyable: true | ||
:start-after: // start-specify-v1 | ||
:end-before: // end-specify-v1 | ||
:emphasize-lines: 3-4 | ||
|
||
.. note:: | ||
|
||
After you create a ``MongoDB\Client`` instance with | ||
a specified API version, all commands you run with the client use the specified | ||
version. If you need to run commands using more than one version of the | ||
Check failure on line 65 in source/connect/stable-api.txt
|
||
{+stable-api+}, create a new ``MongoDB\Client`` instance. | ||
|
||
.. _stable-api-options: | ||
|
||
Configure the {+stable-api+} | ||
------------------------ | ||
|
||
The ``MongoDB\Driver\ServerApi`` constructor also accepts the following optional parameters. | ||
You can use these parameters to customize the behavior of the {+stable-api+}. | ||
|
||
.. list-table:: | ||
:header-rows: 1 | ||
:stub-columns: 1 | ||
:widths: 25,75 | ||
|
||
* - Parameter | ||
- Description | ||
|
||
* - strict | ||
- | **Optional**. When ``true``, if you call a command that isn't part of | ||
the declared API version, the server raises an exception. | ||
| | ||
| Default: ``null``. If this parameter is null, the server applies its default | ||
value of ``false``. | ||
|
||
* - deprecationErrors | ||
- | **Optional**. When ``true``, if you call a command that is deprecated in the | ||
declared API version, the server raises an exception. | ||
| | ||
| Default: ``null``. If this parameter is null, the server applies its default | ||
value of ``false``. | ||
|
||
The following code example shows how you can use these parameters when constructing a | ||
``MongoDB\Driver\ServerApi`` object: | ||
|
||
.. literalinclude:: /includes/connect/stable-api.php | ||
:language: php | ||
:copyable: true | ||
:start-after: // start-stable-api-options | ||
:end-before: // end-stable-api-options | ||
:emphasize-lines: 3-4 | ||
|
||
API Documentation | ||
----------------- | ||
|
||
For more information about the ``MongoDB\Client`` class, see the following {+driver-short+} | ||
API documentation: | ||
|
||
- :phpclass:`MongoDB\Client` | ||
|
||
For more information about the ``MongoDB\Driver\ServerApi`` class, see the following | ||
{+extension-short+} API documentation: | ||
|
||
- `MongoDB\\Driver\\ServerApi <https://www.php.net/manual/en/class.mongodb-driver-serverapi.php>`__ |
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,18 @@ | ||
<?php | ||
|
||
// start-specify-v1 | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$uri = "mongodb://<hostname>:<port>"; | ||
|
||
$driverOptions = ['serverApi' => new MongoDB\Driver\ServerApi('1')]; | ||
|
||
$client = new MongoDB\Client($uri, [], $driverOptions); | ||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// end-specify-v1 | ||
|
||
// start-stable-api-options | ||
$uri = "mongodb://<hostname>:<port>"; | ||
|
||
$serverApi = new MongoDB\Driver\ServerApi('1', strict: true, deprecationErrors: true); | ||
$driverOptions = ['serverApi' => $serverApi]; | ||
|
||
$client = new MongoDB\Client($uri, [], $driverOptions); | ||
// end-stable-api-options |
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.