server_api
– Support for MongoDB Versioned API
Starting in MongoDB 5.0, applications can specify the server API version to use when creating a MongoClient. Doing so ensures that the driver behaves in a manner compatible with that server API version, regardless of the server’s actual release version.
Attention
Versioned API requires MongoDB >=5.0.
To configure MongoDB Versioned API, pass the server_api
keyword option to :
The declared API version is applied to all commands run through client
, including those sent through the generic command() helper.
Note
Declaring an API version on the and specifying versioned API options in command() command document is not supported and will lead to undefined behaviour.
To run any command without declaring a server API version or using a different API version, create a separate instance.
Configuring strict
mode will cause the MongoDB server to reject all commands that are not part of the declared ServerApi.version. This includes command options and aggregation pipeline stages.
The option can be used to enable command failures when using functionality that is deprecated from the configured . For example:
Note that at the time of this writing, no deprecated APIs exist.
Classes
class pymongo.server_api.ServerApi
(version, strict=None, deprecation_errors=None)
Options to configure MongoDB Versioned API.
New in version 3.12.
deprecation_errors
The API deprecation errors setting.
When set, this value is sent to the server in the “apiDeprecationErrors” field.
strict
When set, this value is sent to the server in the “apiStrict” field.
version
The API version setting.
This value is sent to the server in the “apiVersion” field.
class pymongo.server_api.ServerApiVersion
An enum that defines values for .
New in version 3.12.