-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-621 Document Versioned API usage #815
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
Merged
Changes from all commits
Commits
Show all changes
4 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
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ Tutorials | |
/tutorial/indexes | ||
/tutorial/tailable-cursor | ||
/tutorial/example-data | ||
/tutorial/versioned-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,94 @@ | ||
============= | ||
Versioned API | ||
============= | ||
|
||
.. default-domain:: mongodb | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
Declaring an API version | ||
------------------------ | ||
|
||
To declare an API version, pass a ``serverApi`` driver option when creating your | ||
client. The value is a | ||
:php:`MongoDB\\Driver\\ServerApi <class.mongodb-driver-serverapi>` instance that | ||
contains API version information. This feature is introduced in MongoDB 5.0, | ||
which will initially support only API version "1". Additional versions may be | ||
introduced in future versions of the server. | ||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
use MongoDB\Client; | ||
use MongoDB\Driver\ServerApi; | ||
|
||
$serverApi = new ServerApi(ServerApi::V1); | ||
$client = new Client('mongodb://127.0.0.1', [], ['serverApi' => $serverApi]); | ||
|
||
// Command includes the declared API version | ||
$client->database->collection->find([]); | ||
|
||
.. note:: | ||
|
||
Only declare an API version when connecting to a deployment that has no | ||
pre-5.0 members. Older servers will error when encountering commands with a | ||
declared API version. | ||
|
||
Strict API | ||
---------- | ||
|
||
By default, declaring an API version guarantees behavior for commands that are | ||
part of the versioned API, but does not forbid using commands that are not part | ||
of the API version. To only allow commands and options that are part of the | ||
versioned API, specify the ``strict`` option when creating the | ||
specify the ``strict`` option when creating the | ||
:php:`MongoDB\\Driver\\ServerApi <class.mongodb-driver-serverapi>` instance: | ||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
use MongoDB\Client; | ||
use MongoDB\Driver\ServerApi; | ||
|
||
$serverApi = new ServerApi(ServerApi::V1, true); | ||
$client = new Client('mongodb://127.0.0.1', [], ['serverApi' => $serverApi]); | ||
|
||
// Will fail as the tailable option is not supported in versioned API | ||
$client->database->collection->find([], ['tailable' => true]); | ||
|
||
Fail on Deprecated Commands | ||
--------------------------- | ||
|
||
The optional ``deprecationErrors`` option causes MongoDB to fail all commands | ||
or behaviors that have been deprecated in the API version. This can be used in | ||
testing to ensure a smooth transition to a future API version. | ||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
use MongoDB\Client; | ||
use MongoDB\Driver\ServerApi; | ||
|
||
$serverApi = new ServerApi(ServerApi::V1, null, true); | ||
$client = new Client('mongodb://127.0.0.1', [], ['serverApi' => $serverApi]); | ||
|
||
.. note:: | ||
|
||
At the time of this writing, no part of API version "1" has been deprecated. | ||
|
||
Usage with the command helper | ||
----------------------------- | ||
|
||
When using the :phpmethod:`MongoDB\\Database::command()` method to run arbitrary | ||
commands, the API version declared to the client is automatically appended to | ||
the command document. Setting any of the ``apiVersion``, ``apiStrict``, or | ||
``apiDeprecationErrors`` command options in the command document and calling | ||
:phpmethod:`MongoDB\\Database::command()` from a client with a declared API | ||
version is not supported and will lead to undefined behavior. |
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.
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.
Was this moved up to alphabetize all of the options? I noticed
allow_invalid_hostname
is still down below.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.
Yes. The first commit moves the deprecated options to the bottom and sorts non-deprecated once alphabetically.