NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #352 most downloaded on PyPI
PyMongo - the Official MongoDB Python driver
Last release 10 days ago
24 Sep 2026
Release timing varies
gaps range from 8 days to 4 months
Nearly every release is documented
notes for 56 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
18 years old
173 releases · first in 2009
CVE-2026-96749 CVE-2026-96748 CVE-2026-96747
Version 4.18.2 is a bug fix release.
Hardened the bson buffer size guard against signed integer overflow. (CVE-2026-96749).
Fixed connection string parsing to percent-decode each host individually. (CVE-2026-96748).
Client-side field level encryption now rejects a KMS endpoint ending in .sock. (CVE-2026-96747).
See the PyMongo 4.18.2 release notes in JIRA for the list of resolved issues in this release.
One column per quarter.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-18-1-released/343338
Version 4.18.1 is a bug fix release.
Use an exact match for the file ID in GridFS delete methods (CVE-2026-88029).
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-18-released/343137
PyMongo 4.18 brings a number of changes including:
Added srvAllowedHostsSuffix as a URI option and keyword argument to ~pymongo.synchronous.mongo_client.MongoClient and ~pymongo.asynchronous.mongo_client.AsyncMongoClient. When connecting via mongodb+srv://, this option overrides the default requirement that SRV-returned hosts share the same parent domain as the seed hostname, allowing hosts under a different domain suffix to be accepted. The suffix must not be a public suffix (per the Public Suffix List). See the ~pymongo.synchronous.mongo_client.MongoClient and ~pymongo.asynchronous.mongo_client.AsyncMongoClient documentation for security considerations.
Dropped support for MongoDB 4.2.
Added support for MongoDB 9.0.
PyPy support is deprecated and will be removed in a future release.
Improved TLS connection performance by reusing TLS sessions across connections to the same server, avoiding a full handshake on each new connection. Session resumption is supported on all Python versions for synchronous clients and on Python 3.11+ for async clients.
Improved performance for MongoDB 9.0's Intelligent Workload Management (IWM) by only retrying overload errors when doing so is expected to not worsen server conditions.
Added support for exhaust cursors (~pymongo.cursor.CursorType.EXHAUST) against mongos 7.1+. An older mongos still raises ~pymongo.errors.InvalidOperation, now on the first iteration of the cursor rather than from ~pymongo.synchronous.collection.Collection.find, since the requirement is checked against the connection in use. Separately, async cursors combining limit with ~pymongo.cursor.CursorType.EXHAUST now raise at find rather than on first iteration, matching the synchronous API.
Redacted potentially sensitive authentication mechanism properties, including AWS session tokens, from the representations of ~pymongo.synchronous.mongo_client.MongoClient and ~pymongo.asynchronous.mongo_client.AsyncMongoClient.
Command monitoring events and command log messages for a single logical operation now share one stable operation_id across all of its retry attempts, so consumers can correlate a retried operation's events. As a result, operation_id is no longer equal to the per-attempt request_id for these operations.
Added validation of OP_COMPRESSED decompressed message size against max_message_size to prevent memory exhaustion from maliciously crafted compressed server responses.
Improved the performance and memory usage of decoding large documents to ~bson.raw_bson.RawBSONDocument. Documents and subdocuments that are 4KB or greater and decoded from an immutable buffer are now exposed as read-only memoryview slices instead of bytes copies. Documents decoded from mutable buffers such as a bytearray are always bytes copies.
bson.get_data_and_view now returns a view of a private bytes copy for buffer-protocol inputs other than bytes or bytearray.
Improved the performance of lazily decoding a ~bson.raw_bson.RawBSONDocument when the C extension is available.
Fixed a potential out-of-bounds read in the C extension when decoding an array of BSON documents. An embedded document whose declared length exceeds the bytes remaining in the array now raises ~bson.errors.InvalidBSON instead of reading past the end of the buffer.
Fixed bson.json_util.loads to reject $timestamp values containing fields other than t and i.
Fixed a bug on Windows, and on macOS when using PyOpenSSL, where SSL_CERT_FILE/SSL_CERT_DIR were merged with, rather than replacing, the OS/certifi certificate store.
Added general availability support for Queryable Encryption prefix, suffix, and substring queries against MongoDB 9.0+. These queries require libmongocrypt 1.20.0 or later:
Added ~pymongo.encryption.Algorithm.STRING and ~pymongo.encryption_options.StringOpts, replacing Algorithm.TEXTPREVIEW and TextOpts, which are now deprecated.
Added ~pymongo.encryption.QueryType.PREFIX, ~pymongo.encryption.QueryType.SUFFIX, and ~pymongo.encryption.QueryType.SUBSTRING. The corresponding PREFIXPREVIEW, SUFFIXPREVIEW, and SUBSTRINGPREVIEW query types remain for experimental use with MongoDB versions before 9.0.
Added the string_opts parameter to ~pymongo.encryption.ClientEncryption.encrypt and ~pymongo.asynchronous.encryption.AsyncClientEncryption.encrypt, deprecating text_opts. pymongocrypt added text_opts in 1.16 and renamed it to string_opts in 1.19, and accepts only one of the two names per release, so passing text_opts with pymongocrypt 1.19 or later, string_opts with pymongocrypt 1.16 through 1.18, or both names at once, raises ~pymongo.errors.ConfigurationError.
Aggregation helpers now raise ~pymongo.errors.ConfigurationError when passed an aggregate or pipeline keyword argument. Previously these keys silently replaced the target namespace and pipeline of the generated aggregate command. This affects ~pymongo.asynchronous.collection.AsyncCollection.aggregate and ~pymongo.synchronous.collection.Collection.aggregate, ~pymongo.asynchronous.collection.AsyncCollection.aggregate_raw_batches and ~pymongo.synchronous.collection.Collection.aggregate_raw_batches, ~pymongo.asynchronous.database.AsyncDatabase.aggregate and ~pymongo.synchronous.database.Database.aggregate, and ~pymongo.asynchronous.collection.AsyncCollection.list_search_indexes and ~pymongo.synchronous.collection.Collection.list_search_indexes.
PYTHON-5757 Deprecate Python 2 methods in SON by @aclark4life in #2732
Full Changelog: 4.16.0...4.17.0
PyMongo 4.17 brings a number of changes including:
has_key, iterkeys and itervalues in bson.son.SON have been deprecated and will be removed in PyMongo 5.0. These methods were deprecated in favor of the standard dictionary containment operator in and the keys() and values() methods, respectively.
Added the ~pymongo.asynchronous.client_session.AsyncClientSession.bind and ~pymongo.client_session.ClientSession.bind methods that allow users to bind a session to all database operations within the scope of a context manager instead of having to explicitly pass the session to each individual operation. See the Transactions docs for examples and more information.
Added support for MongoDB's Intelligent Workload Management (IWM) and ingress connection rate limiting features in MongoDB server version 9.0. The driver will gracefully handle write-blocking scenarios and optimizes connection establishment during high-load conditions to maintain application availability.
PyMongo now requires dnspython>=2.6.1, since dnspython 1.0 is no longer maintained. The minimum version is 2.6.1 to account for CVE-2023-29483 _.
PyMongo 4.16 brings a number of changes including:
Removed invalid documents from bson.errors.InvalidDocument error messages as doing so may leak sensitive user data. Instead, invalid documents are stored in bson.errors.InvalidDocument.document.
PyMongo now requires dnspython>=2.6.1, since dnspython 1.0 is no longer maintained. The minimum version is 2.6.1 to account for CVE-2023-29483.
Removed support for Eventlet. Eventlet is actively being sunset by its maintainers and has compatibility issues with PyMongo's dnspython dependency.
Use Zstandard support from the standard library for Python 3.14+, and use backports.zstd for older versions.
Fixed return type annotation for find_one_and_* methods on ~pymongo.asynchronous.collection.AsyncCollection and ~pymongo.synchronous.collection.Collection to include None.
Added support for NumPy 1D-arrays in bson.binary.BinaryVector.
Prevented ~pymongo.encryption.ClientEncryption from loading the crypt shared library to fix "MongoCryptError: An existing crypt_shared library is loaded by the application" unless the linked library search path is set.
Nothing published for this version
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-15-5-released/332185
Version 4.15.5 is a bug fix release.
Fixed a bug that could cause AutoReconnect("connection pool paused") errors when cursors fetched more documents from the database after SDAM heartbeat failures.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-15-4-released/331292
Version 4.15.4 is a bug fix release.
Relaxed the callback type of ~pymongo.asynchronous.client_session.AsyncClientSession.with_transaction to allow the broader Awaitable type rather than only Coroutine objects.
Added the missing Python 3.14 trove classifier to the package metadata.
See the PyMongo 4.15.4 release notes in JIRA for the list of resolved issues in this release.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-15-3-released/329778
Version 4.15.3 is a bug fix release.
Fixed a memory leak when raising bson.errors.InvalidDocument with C extensions.
Fixed the return type of the ~pymongo.asynchronous.collection.AsyncCollection.distinct, ~pymongo.synchronous.collection.Collection.distinct, pymongo.asynchronous.cursor.AsyncCursor.distinct, and pymongo.asynchronous.cursor.AsyncCursor.distinct methods.
See the PyMongo 4.15.3 release notes in JIRA for the list of resolved issues in this release.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-15-2-released/329543
Version 4.15.2 is a bug fix release.
Add wheels for Python 3.14 and 3.14t that were missing from 4.15.0 release. Drop the 3.13t wheel.
See the PyMongo 4.15.2 release notes in JIRA for the list of resolved issues in this release.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-15-1-released/328837
Version 4.15.1 is a bug fix release.
Fixed a bug in ~pymongo.synchronous.encryption.ClientEncryption.encrypt and ~pymongo.asynchronous.encryption.AsyncClientEncryption.encrypt that would cause a TypeError when using pymongocrypt<1.16 by passing an unsupported type_opts parameter even if Queryable Encryption text queries beta was not used.
Fixed a bug in AsyncMongoClient that caused a ServerSelectionTimeoutError when used with uvicorn, FastAPI, or uvloop.
See the PyMongo 4.15.1 release notes in JIRA for the list of resolved issues in this release.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-15-released/328574
PyMongo 4.15 brings a number of changes including:
Added ~pymongo.encryption_options.TextOpts, ~pymongo.encryption.Algorithm.TEXTPREVIEW, ~pymongo.encryption.QueryType.PREFIXPREVIEW, ~pymongo.encryption.QueryType.SUFFIXPREVIEW, ~pymongo.encryption.QueryType.SUBSTRINGPREVIEW, as part of the experimental Queryable Encryption text queries beta. pymongocrypt>=1.16 is required for text query support.
Added bson.decimal128.DecimalEncoder and bson.decimal128.DecimalDecoder to support encoding and decoding of BSON Decimal128 values to decimal.Decimal values using the TypeRegistry API.
Added support for Windows arm64 wheels.
Community notes: https://www.mongodb.com/community/forums/t/pymongo-4-14-1-released/327511
Version 4.14.1 is a bug fix release.
Fixed a bug in MongoClient.append_metadata() and AsyncMongoClient.append_metadata() that allowed duplicate DriverInfo.name to be appended to the metadata.
See the PyMongo 4.14.1 release notes in JIRA for the list of resolved issues in this release.
Introduces a minor breaking change. When encoding bson.binary.BinaryVector, a ValueError will be raised if the 'padding' metadata field is < 0 or > 7,…
Warning
PyMongo 4.14 drops support for MongoDB 4.0. PyMongo now supports MongoDB 4.2+.
PyMongo 4.14 brings a number of changes including:
Dropped support for MongoDB 4.0.
Added preliminary support for Python 3.14 and 3.14 with free-threading. We do not yet support the following with Python 3.14:
Subinterpreters (concurrent.interpreters)
Free-threading with Encryption
mod_wsgi
Removed experimental support for free-threading support in Python 3.13.
Added bson.codec_options.TypeRegistry.codecs and bson.codec_options.TypeRegistry.fallback_encoder properties to allow users to directly access the type codecs and fallback encoder for a given bson.codec_options.TypeRegistry.
Added pymongo.asynchronous.mongo_client.AsyncMongoClient.append_metadata and pymongo.mongo_client.MongoClient.append_metadata to allow instantiated MongoClients to send client metadata on-demand
Improved performance of selecting a server with the Primary selector.
Introduces a minor breaking change. When encoding bson.binary.BinaryVector, a ValueError will be raised if the 'padding' metadata field is < 0 or > 7, or non-zero for any type other than PACKED_BIT.
Changed ~pymongo.uri_parser.parse_uri's options return value to be type dict instead of _CaseInsensitiveDictionary.
See the PyMongo 4.14 release notes in JIRA for the list of resolved issues in this release.
Version 4.13.2 is a bug fix release.
Version 4.13.2 is a bug fix release.
Fixed a bug where AsyncMongoClient would block the event loop while creating new connections, potentially significantly increasing latency for ongoing operations.
See the PyMongo 4.13.2 release notes in JIRA for the list of resolved issues in this release.
Version 4.13.1 is a bug fix release.
Version 4.13.1 is a bug fix release.
Fixed a bug that could raise ServerSelectionTimeoutError when using timeouts with AsyncMongoClient.
Fixed a bug that could raise NetworkTimeout errors on Windows.
See the PyMongo 4.13.1 release notes in JIRA for the list of resolved issues in this release.
When encoding, this is enforced and is a breaking change. It is not yet enforced when decoding, so reading from the database will not fail, however a…
PyMongo 4.13 brings a number of changes including:
The asynchronous API is now stable and no longer in beta. See the pymongo.asynchronous docs or the migration guide for more information.
Fixed a bug where pymongo.write_concern.WriteConcern repr was not eval-able when using w="majority".
When padding is set, ignored bits in a BSON BinaryVector of PACKED_BIT dtype should be set to zero. When encoding, this is enforced and is a breaking change. It is not yet enforced when decoding, so reading from the database will not fail, however a warning will be triggered. From PyMongo 5.0, this rule will be enforced for both encoding and decoding.
See the PyMongo 4.13 release notes in JIRA for the list of resolved issues in this release.
Nothing published for this version
Version 4.12.1 is a bug fix release.
Version 4.12.1 is a bug fix release.
Fixed a bug that could raise UnboundLocalError when creating asynchronous connections over SSL.
Fixed a bug causing SRV hostname validation to fail when resolver and resolved hostnames are identical with three domain levels.
Fixed a bug that caused direct use of pymongo.uri_parser to raise an AttributeError.
Fixed a bug where clients created with connect=False and a "mongodb+srv://" connection string could cause public pymongo.MongoClient and pymongo.AsyncMongoClient attributes (topology_description, nodes, address, primary, secondaries, arbiters) to incorrectly return a Database, leading to type errors such as: "NotImplementedError: Database objects do not implement truth value testing or bool()".
Removed Eventlet testing against Python versions newer than 3.9 since Eventlet is actively being sunset by its maintainers and has compatibility issues with PyMongo's dnspython dependency.
Fixed a bug where MongoDB cluster topology changes could cause asynchronous operations to take much longer to complete due to holding the Topology lock while closing stale connections.
Fixed a bug that would cause AsyncMongoClient to attempt to use PyOpenSSL when available, resulting in errors such as "pymongo.errors.ServerSelectionTimeoutError: 'SSLContext' object has no attribute 'wrap_bio'".
See the PyMongo 4.12.1 release notes in JIRA for the list of resolved issues in this release.
Deprecated the hedge parameter for ~pymongo.read_preferences.PrimaryPreferred, ~pymongo.read_preferences.Secondary, ~pymongo.read_preferences.Secondar…
Warning
Driver support for MongoDB 4.0 reached end of life in April 2025. PyMongo 4.12 will be the last release to support MongoDB 4.0.
PyMongo 4.12 brings a number of changes including:
Support for configuring DEK cache lifetime via the key_expiration_ms argument to ~pymongo.encryption_options.AutoEncryptionOpts.
Support for $lookup in CSFLE and QE supported on MongoDB 8.1+.
pymongocrypt>=1.13 is now required for In-Use Encryption support.
Added gridfs.asynchronous.grid_file.AsyncGridFSBucket.rename_by_name and gridfs.grid_file.GridFSBucket.rename_by_name for more performant renaming of a file with multiple revisions.
Added gridfs.asynchronous.grid_file.AsyncGridFSBucket.delete_by_name and gridfs.grid_file.GridFSBucket.delete_by_name for more performant deletion of a file with multiple revisions.
AsyncMongoClient no longer performs DNS resolution for "mongodb+srv://" connection strings on creation. To avoid blocking the asyncio loop, the resolution is now deferred until the client is first connected.
Added index hinting support to the ~pymongo.asynchronous.collection.AsyncCollection.distinct and ~pymongo.collection.Collection.distinct commands.
Deprecated the hedge parameter for ~pymongo.read_preferences.PrimaryPreferred, ~pymongo.read_preferences.Secondary, ~pymongo.read_preferences.SecondaryPreferred, ~pymongo.read_preferences.Nearest. Support for hedge will be removed in PyMongo 5.0.
Removed PyOpenSSL support from the asynchronous API due to limitations of the CPython asyncio.Protocol SSL implementation.
Allow valid SRV hostnames with less than 3 parts.
See the PyMongo 4.12 release notes in JIRA for the list of resolved issues in this release.
Nothing published for this version
Version 4.11.2 is a bug fix release.
Version 4.11.2 is a bug fix release.
Fixed a bug where ~pymongo.database.Database.command would fail when attempting to run the bulkWrite command.
See the PyMongo 4.11.2 release notes in JIRA for the list of resolved issues in this release.
Fixed support for prebuilt ppc64le and s390x wheels.
Fixed support for prebuilt ppc64le and s390x wheels.
Nothing published for this version
Version 4.10.1 is a bug fix release.
Version 4.10.1 is a bug fix release.
Fixed a bug where ~pymongo.results.UpdateResult.did_upsert would raise a TypeError.
Fixed Binary BSON subtype (9) support on big-endian operating systems (such as zSeries).
See the PyMongo 4.10.1 release notes in JIRA for the list of resolved issues in this release.
Added provisional (BETA) support for a new Binary BSON subtype (9) used for efficient storage and retrieval of vectors: densely packed arrays of numbe
Added provisional (BETA) support for a new Binary BSON subtype (9) used for efficient storage and retrieval of vectors: densely packed arrays of numbers, all of the same type. This includes new methods ~bson.binary.Binary.from_vector and ~bson.binary.Binary.as_vector.
Added C extension use to client metadata, for example: {"driver": {"name": "PyMongo|c", "version": "4.10.0"}, ...}
Fixed a bug where ~pymongo.asynchronous.mongo_client.AsyncMongoClient could deadlock.
Fixed a bug where PyMongo could fail to import on Windows if asyncio is misconfigured.
See the PyMongo 4.10 release notes in JIRA for the list of resolved issues in this release.
Fixed a bug where ~pymongo.asynchronous.mongo_client.AsyncMongoClient could deadlock.
Fixed a bug where ~pymongo.asynchronous.mongo_client.AsyncMongoClient could deadlock.
Fixed a bug where PyMongo could fail to import on Windows if asyncio is misconfigured.
Fixed a bug where ~pymongo.results.UpdateResult.did_upsert would raise a TypeError.
See the PyMongo 4.9.2 release notes in JIRA for the list of resolved issues in this release.
Add missing documentation about the fact the async API is in beta state.
Add missing documentation about the fact the async API is in beta state.
See the PyMongo 4.9.1 release notes in JIRA for the list of resolved issues in this release.
.. warning:: Driver support for MongoDB 3.6 reached end of life in April 2024. PyMongo 4.9 will be the last release to support MongoDB 3.6.
Warning
Driver support for MongoDB 3.6 reached end of life in April 2024. PyMongo 4.9 will be the last release to support MongoDB 3.6.
Warning
PyMongo 4.9 refactors a large portion of internal APIs to support the new asynchronous API beta. As a result, versions of Motor older than 3.6 are not compatible with PyMongo 4.9. Existing users of these versions must either upgrade to Motor 3.6 and PyMongo 4.9, or cap their PyMongo version to < 4.9. Any applications that use private APIs may also break as a result of these internal changes.
PyMongo 4.9 brings a number of improvements including:
Added support for MongoDB 8.0.
Added support for Python 3.13.
A new beta asynchronous API with full asyncio support. This new asynchronous API is a work-in-progress that may change during the beta period before the full release.
Added support for In-Use Encryption range queries with MongoDB 8.0. Added ~pymongo.encryption.Algorithm.RANGE. sparsity and trim_factor are now optional in ~pymongo.encryption_options.RangeOpts.
Added support for the "delegated" option for the KMIP master_key in ~pymongo.encryption.ClientEncryption.create_data_key.
pymongocrypt>=1.10 is now required for In-Use Encryption support.
Added ~pymongo.cursor.Cursor.to_list to ~pymongo.cursor.Cursor, ~pymongo.command_cursor.CommandCursor, ~pymongo.asynchronous.cursor.AsyncCursor, and ~pymongo.asynchronous.command_cursor.AsyncCommandCursor as an asynchronous-friendly alternative to list(cursor).
Added ~pymongo.mongo_client.MongoClient.bulk_write to ~pymongo.mongo_client.MongoClient and ~pymongo.asynchronous.mongo_client.AsyncMongoClient, enabling users to perform insert, update, and delete operations against mixed namespaces in a minimized number of round trips. Please see Client Bulk Write for more information.
Added support for the namespace parameter to the ~pymongo.operations.InsertOne, ~pymongo.operations.ReplaceOne, ~pymongo.operations.UpdateOne, ~pymongo.operations.UpdateMany, ~pymongo.operations.DeleteOne, and ~pymongo.operations.DeleteMany operations, so they can be used in the new ~pymongo.mongo_client.MongoClient.bulk_write.
Added repr support to bson.tz_util.FixedOffset.
Fixed a bug where PyMongo would raise InvalidBSON: unhashable type: 'tzfile' when using ~bson.codec_options.DatetimeConversion.DATETIME_CLAMP or ~bson.codec_options.DatetimeConversion.DATETIME_AUTO with a timezone from dateutil.
Fixed a bug where PyMongo would raise InvalidBSON: date value out of range when using ~bson.codec_options.DatetimeConversion.DATETIME_CLAMP or ~bson.codec_options.DatetimeConversion.DATETIME_AUTO with a non-UTC timezone.
Added a warning to unclosed MongoClient instances telling users to explicitly close clients when finished with them to avoid leaking resources. For example:
sys:1: ResourceWarning: Unclosed MongoClient opened at:
File "/Users/<user>/my_file.py", line 8, in <module>``
client = MongoClient()
Call MongoClient.close() to safely shut down your client and free up resources.
The default value for connect in MongoClient is changed to False when running on unction-as-a-service (FaaS) like AWS Lambda, Google Cloud Functions, and Microsoft Azure Functions. On some FaaS systems, there is a fork() operation at function startup. By delaying the connection to the first operation, we avoid a deadlock. See multiple forks for more information.
See the PyMongo 4.9 release notes in JIRA for the list of resolved issues in this release.
Unavoidable breaking changes ............................
Warning
PyMongo 4.8 drops support for Python 3.7 and PyPy 3.8: Python 3.8+ or PyPy 3.9+ is now required.
PyMongo 4.8 brings a number of improvements including:
The handshake metadata for "os.name" on Windows has been simplified to "Windows" to improve import time.
The repr of bson.binary.Binary is now redacted when the subtype is SENSITIVE_SUBTYPE(8).
Secure Software Development Life Cycle automation for release process. GitHub Releases now include a Software Bill of Materials, and signature files corresponding to the distribution files released on PyPI.
Fixed a bug in change streams where both startAtOperationTime and resumeToken could be added to a retry attempt, which caused the retry to fail.
Fallback to stdlib ssl module when pyopenssl import fails with AttributeError.
Improved performance of MongoClient operations, especially when many operations are being run concurrently.
Since we are now using hatch as our build backend, we no longer have a usable setup.py file and require installation using pip. Attempts to invoke the setup.py file will raise an exception. Additionally, pip >= 21.3 is now required for editable installs.
We no longer support the srv extra, since dnspython is included as a dependency in PyMongo 4.7+. Instead of pip install pymongo[srv], use pip install pymongo.
We no longer support the tls extra, which was only valid for Python 2. Instead of pip install pymongo[tls], use pip install pymongo.
See the PyMongo 4.8 release notes in JIRA for the list of resolved issues in this release.
Nothing published for this version
Version 4.7.3 has further fixes for lazily loading modules.
Version 4.7.3 has further fixes for lazily loading modules.
Use deferred imports instead of importlib lazy module loading.
Improve import time on Windows.
Reduce verbosity of "Waiting for suitable server to become available" log message from info to debug.
See the PyMongo 4.7.3 release notes in JIRA for the list of resolved issues in this release.
Version 4.7.2 fixes a bug introduced in 4.7.0:
Version 4.7.2 fixes a bug introduced in 4.7.0:
Fixed a bug where PyMongo could not be used with the Nuitka compiler.
See the PyMongo 4.7.2 release notes in JIRA for the list of resolved issues in this release.
Version 4.7.1 fixes a bug introduced in 4.7.0:
Version 4.7.1 fixes a bug introduced in 4.7.0:
Fixed a bug where PyMongo would cause an AttributeError if dns.resolver was imported and referenced after PyMongo was imported.
Clarified the behavior of the TOKEN_RESOURCE auth mechanism property for MONGODB-OIDC.
See the PyMongo 4.7.1 release notes in JIRA for the list of resolved issues in this release.
.. warning:: PyMongo depends on dnspython, which released version 2.6.1 with a fix for CVE-2023-29483 _. We do not explicitly require that version, bu…
PyMongo 4.7 brings a number of improvements including:
Added support for MONGODB-OIDC authentication. The MONGODB-OIDC mechanism authenticates using an OpenID Connect (OIDC) access token. The driver supports OIDC for workload identity, defined as an identity you assign to a software workload (such as an application, service, script, or container) to authenticate and access other services and resources. Please see Authentication for more information.
Added support for Python's native logging library, enabling developers to customize the verbosity of log messages for their applications. Please see Logging for more information.
Significantly improved the performance of encoding BSON documents to JSON.
Added support for named KMS providers for client side field level encryption. Previously supported KMS providers were only: aws, azure, gcp, kmip, and local. The KMS provider is now expanded to support name suffixes (e.g. local:myname). Named KMS providers enables more than one of each KMS provider type to be configured. See the docstring for ~pymongo.encryption_options.AutoEncryptionOpts. Note that named KMS providers requires pymongocrypt >=1.9 and libmongocrypt >=1.9.
Added the pymongo.hello.Hello.connection_id, pymongo.monitoring.CommandStartedEvent.server_connection_id, pymongo.monitoring.CommandSucceededEvent.server_connection_id, and pymongo.monitoring.CommandFailedEvent.server_connection_id properties.
Fixed a bug where inflating a ~bson.raw_bson.RawBSONDocument containing a ~bson.code.Code would cause an error.
~pymongo.encryption.ClientEncryption.encrypt and ~pymongo.encryption.ClientEncryption.encrypt_expression now allow key_id to be passed in as a uuid.UUID.
Fixed a bug where ~bson.int64.Int64 instances could not always be encoded by orjson. The following now works:
>>> import orjson
>>> from bson import json_util
>>> orjson.dumps({'a': Int64(1)}, default=json_util.default, option=orjson.OPT_PASSTHROUGH_SUBCLASS)
Fixed a bug appearing in Python 3.12 where "RuntimeError: can't create new thread at interpreter shutdown" could be written to stderr when a MongoClient's thread starts as the python interpreter is shutting down.
Added a warning when connecting to DocumentDB and CosmosDB clusters. For more information regarding feature compatibility and support please visit mongodb.com/supportability/documentdb and mongodb.com/supportability/cosmosdb.
Added the pymongo.monitoring.ConnectionCheckedOutEvent.duration, pymongo.monitoring.ConnectionCheckOutFailedEvent.duration, and pymongo.monitoring.ConnectionReadyEvent.duration properties.
Added the type and kwargs arguments to ~pymongo.operations.SearchIndexModel to enable creating vector search indexes in MongoDB Atlas.
Fixed a bug where read_concern and write_concern were improperly added to ~pymongo.collection.Collection.list_search_indexes queries.
Deprecated pymongo.write_concern.WriteConcern.wtimeout and pymongo.mongo_client.MongoClient.wTimeoutMS. Use ~pymongo.timeout instead.
Warning
PyMongo depends on dnspython, which released version 2.6.1 with a fix for CVE-2023-29483. We do not explicitly require that version, but we strongly recommend that you install at least that version in your environment.
Replaced usage of bson.son.SON on all internal classes and commands to dict, options.pool_options.metadata is now of type dict as opposed to bson.son.SON. Here's some examples of how this changes expected output as well as how to convert from dict to bson.son.SON:
# Before
>>> from pymongo import MongoClient
>>> client = MongoClient()
>>> client.options.pool_options.metadata
SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')])
# After
>>> client.options.pool_options.metadata
{'driver': {'name': 'PyMongo', 'version': '4.7.0.dev0'}, 'os': {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}, 'platform': 'CPython 3.11.6.final.0'}
# To convert from dict to SON
# This will only convert the first layer of the dictionary
>>> data_as_dict = client.options.pool_options.metadata
>>> SON(data_as_dict)
SON([('driver', {'name': 'PyMongo', 'version': '4.7.0.dev0'}), ('os', {'type': 'Darwin', 'name': 'Darwin', 'architecture': 'arm64', 'version': '14.3'}), ('platform', 'CPython 3.11.6.final.0')])
# To convert from dict to SON on a nested dictionary
>>> def dict_to_SON(data_as_dict: dict[Any, Any]):
... data_as_SON = SON()
... for key, value in data_as_dict.items():
... data_as_SON[key] = dict_to_SON(value) if isinstance(value, dict) else value
... return data_as_SON
>>>
>>> dict_to_SON(data_as_dict)
SON([('driver', SON([('name', 'PyMongo'), ('version', '4.7.0.dev0')])), ('os', SON([('type', 'Darwin'), ('name', 'Darwin'), ('architecture', 'arm64'), ('version', '14.3')])), ('platform', 'CPython 3.11.6.final.0')])
PyMongo now uses lazy imports for external dependencies. If you are relying on any kind of monkey-patching of the standard library, you may need to explicitly import those external libraries in addition to pymongo before applying the patch. Note that we test with gevent and eventlet patching, and those continue to work.
The "aws" extra now requires minimum version of 1.1.0 for pymongo_auth_aws.
PyMongo 4.6.3 fixes the following bug:
PyMongo 4.6.3 fixes the following bug:
Fixed a potential memory access violation when decoding invalid bson.
See the PyMongo 4.6.3 release notes in JIRA for the list of resolved issues in this release.
PyMongo 4.6.2 fixes the following bug:
PyMongo 4.6.2 fixes the following bug:
Fixed a bug appearing in Python 3.12 where "RuntimeError: can't create new thread at interpreter shutdown" could be written to stderr when a MongoClient's thread starts as the python interpreter is shutting down.
See the PyMongo 4.6.2 release notes in JIRA for the list of resolved issues in this release.
PyMongo 4.6.1 fixes the following bug:
PyMongo 4.6.1 fixes the following bug:
Ensure retryable read OperationFailure errors re-raise exception when 0 or NoneType error code is provided.
See the PyMongo 4.6.1 release notes in JIRA for the list of resolved issues in this release.
PyMongo 4.6 brings a number of improvements including:
PyMongo 4.6 brings a number of improvements including:
Added the serverMonitoringMode URI and keyword argument to ~pymongo.mongo_client.MongoClient.
Improved client performance and reduced connection requirements in Function-as-a-service (FaaS) environments like AWS Lambda, Google Cloud Functions, and Microsoft Azure Functions.
Added the pymongo.monitoring.CommandSucceededEvent.database_name property.
Added the pymongo.monitoring.CommandFailedEvent.database_name property.
Allow passing a dict to sort/create_index/hint.
Added repr support to the write result classes: ~pymongo.results.BulkWriteResult, ~pymongo.results.DeleteResult, ~pymongo.results.InsertManyResult, ~pymongo.results.InsertOneResult, ~pymongo.results.UpdateResult, and ~pymongo.encryption.RewrapManyDataKeyResult. For example:
>>> client.t.t.insert_one({})
InsertOneResult(ObjectId('65319acdd55bb3a27ab5502b'), acknowledged=True)
>>> client.t.t.insert_many([{} for _ in range(3)])
InsertManyResult([ObjectId('6532f85e826f2b6125d6ce39'), ObjectId('6532f85e826f2b6125d6ce3a'), ObjectId('6532f85e826f2b6125d6ce3b')], acknowledged=True)
~pymongo.uri_parser.parse_uri now considers the delimiting slash (/) between hosts and connection options optional. For example, "mongodb://example.com?tls=true" is now a valid URI.
Fixed a bug where PyMongo would incorrectly promote all cursors to exhaust cursors when connected to load balanced MongoDB clusters or Serverless clusters.
Added the network compression documentation page.
Added more timeout information to network errors.
See the PyMongo 4.6 release notes in JIRA for the list of resolved issues in this release.
PyMongo 4.5 brings a number of improvements including:
PyMongo 4.5 brings a number of improvements including:
Added new helper methods for Atlas Search Index (requires MongoDB Server 7.0+): ~pymongo.collection.Collection.list_search_indexes, ~pymongo.collection.Collection.create_search_index, ~pymongo.collection.Collection.create_search_indexes, ~pymongo.collection.Collection.drop_search_index, ~pymongo.collection.Collection.update_search_index
Added ~pymongo.database.Database.cursor_command and ~pymongo.command_cursor.CommandCursor.try_next to support executing an arbitrary command that returns a cursor.
cryptography 2.5 or later is now required for OCSP support.
Improved bson encoding and decoding performance by up to 134%(PYTHON-3729, PYTHON-3797, PYTHON-3816, PYTHON-3817, PYTHON-3820, PYTHON-3824, and PYTHON-3846).
Warning
PyMongo no longer supports PyPy3 versions older than 3.8. Users must upgrade to PyPy3.8+.
See the PyMongo 4.5 release notes in JIRA for the list of resolved issues in this release.
Version 4.4.1 fixes the following bugs:
Version 4.4.1 fixes the following bugs:
Fixed a bug where pymongo would raise a ConfigurationError: Invalid SRV host error when connecting to a "mongodb+srv://" URI that included capital letters in the SRV hosts returned from DNS. (PYTHON-3800).
Fixed a minor reference counting bug in the C extension (PYTHON-3798).
See the PyMongo 4.4.1 release notes in JIRA for the list of resolved issues in this release.
pymongocrypt 1.6.0 or later is now required for In-Use Encryption _ support. MongoDB Server 7.0 introduced a backwards breaking change to the QE proto…
PyMongo 4.4 brings a number of improvements including:
Added support for MongoDB 7.0.
Added support for Python 3.11.
Added support for passing a list containing (key, direction) pairs or keys to ~pymongo.collection.Collection.create_index.
Improved bson encoding performance (PYTHON-3717 and PYTHON-3718).
Improved support for Pyright to improve typing support for IDEs like Visual Studio Code or Visual Studio.
Improved support for type-checking with MyPy "strict" mode (--strict).
Added ~pymongo.encryption.ClientEncryption.create_encrypted_collection, ~pymongo.errors.EncryptedCollectionError, ~pymongo.encryption.ClientEncryption.encrypt_expression, ~pymongo.encryption_options.RangeOpts, and ~pymongo.encryption.Algorithm.RANGEPREVIEW as part of the experimental Queryable Encryption beta.
pymongocrypt 1.6.0 or later is now required for In-Use Encryption support. MongoDB Server 7.0 introduced a backwards breaking change to the QE protocol. Users taking advantage of the Queryable Encryption beta must now upgrade to MongoDB 7.0+ and PyMongo 4.4+.
Previously, PyMongo's docs recommended using datetime.datetime.utcnow and datetime.datetime.utcfromtimestamp. utcnow and utcfromtimestamp are deprecated in Python 3.12, for reasons explained in this Github issue. Instead, users should use datetime.datetime.now(tz=timezone.utc) and datetime.datetime.fromtimestamp(tz=timezone.utc) instead.
See the PyMongo 4.4 release notes in JIRA for the list of resolved issues in this release.
Nothing published for this version
Version 4.3.3 documents support for the following:
Version 4.3.3 documents support for the following:
CSFLE on-demand credentials for cloud KMS providers.
Authentication support for EKS Clusters.
Added the timeout example page to improve the documentation for pymongo.timeout.
Fixed a performance regression in ~gridfs.GridFSBucket.download_to_stream and ~gridfs.GridFSBucket.download_to_stream_by_name by reading in chunks instead of line by line (PYTHON-3502).
Improved performance of gridfs.grid_file.GridOut.read and gridfs.grid_file.GridOut.readline (PYTHON-3508).
See the PyMongo 4.3.3 release notes in JIRA for the list of resolved issues in this release.
Note: We withheld uploading tags 4.3.0 and 4.3.1 to PyPI due to a version handling error and a necessary documentation update.
Note: We withheld uploading tags 4.3.0 and 4.3.1 to PyPI due to a version handling error and a necessary documentation update.
dnspython is now a required dependency. This change makes PyMongo easier to install for use with "mongodb+srv://" connection strings and MongoDB Atlas.
PyMongo 4.3 brings a number of improvements including:
Added support for decoding BSON datetimes outside of the range supported by Python's ~datetime.datetime builtin. See handling out of range datetimes for examples, as well as bson.datetime_ms.DatetimeMS, bson.codec_options.DatetimeConversion, and bson.codec_options.CodecOptions's datetime_conversion parameter for more details (PYTHON-1824).
PyMongo now resets its locks and other shared state in the child process after a os.fork to reduce the frequency of deadlocks. Note that deadlocks are still possible because libraries that PyMongo depends like OpenSSL cannot be made fork() safe in multithreaded applications. (PYTHON-2484). For more info see multiple forks.
When used with MongoDB 6.0+, ~pymongo.change_stream.ChangeStream s now allow for new types of events (such as DDL and C2C replication events) to be recorded with the new parameter show_expanded_events that can be passed to methods such as ~pymongo.collection.Collection.watch.
PyMongo now internally caches AWS credentials that it fetches from AWS endpoints, to avoid rate limitations. The cache is cleared when the credentials expire or an error is encountered.
When using the MONGODB-AWS authentication mechanism with the aws extra, the behavior of credential fetching has changed with pymongo_auth_aws>=1.1.0. Please see Authentication for more information.
Fixed a bug where ~pymongo.change_stream.ChangeStream would allow an app to retry calling next() or try_next() even after non-resumable errors (PYTHON-3389).
Fixed a bug where the client could be unable to discover the new primary after a simultaneous replica set election and reconfig (PYTHON-2970).
See the PyMongo 4.3 release notes in JIRA for the list of resolved issues in this release.
Support for the Queryable Encryption beta with MongoDB 6.0. Note that backwards-breaking changes may be made before the final release. See automatic q…
Warning
PyMongo 4.2 drops support for Python 3.6: Python 3.7+ is now required.
PyMongo 4.2 brings a number of improvements including:
Support for MongoDB 6.0.
Support for the Queryable Encryption beta with MongoDB 6.0. Note that backwards-breaking changes may be made before the final release. See automatic queryable client-side encryption for example usage.
Provisional (beta) support for pymongo.timeout to apply a single timeout to an entire block of pymongo operations. See timeout for examples.
Added the timeoutMS URI and keyword argument to ~pymongo.mongo_client.MongoClient.
Added the pymongo.errors.PyMongoError.timeout property which is True when the error was caused by a timeout.
Added the check_exists argument to ~pymongo.database.Database.create_collection that when True (the default) runs an additional listCollections command to verify that the collection does not exist already.
Added the following key management APIs to ~pymongo.encryption.ClientEncryption:
~pymongo.encryption.ClientEncryption.get_key
~pymongo.encryption.ClientEncryption.get_keys
~pymongo.encryption.ClientEncryption.delete_key
~pymongo.encryption.ClientEncryption.add_key_alt_name
~pymongo.encryption.ClientEncryption.get_key_by_alt_name
~pymongo.encryption.ClientEncryption.remove_key_alt_name
~pymongo.encryption.ClientEncryption.rewrap_many_data_key
~pymongo.encryption.RewrapManyDataKeyResult
Support for the crypt_shared library to replace mongocryptd using the new crypt_shared_lib_path and crypt_shared_lib_required arguments to ~pymongo.encryption_options.AutoEncryptionOpts.
Fixed a bug where ~pymongo.collection.Collection.estimated_document_count would fail with a "CommandNotSupportedOnView" error on views (PYTHON-2885).
Fixed a bug where invalid UTF-8 strings could be passed as patterns for ~bson.regex.Regex objects. bson.encode now correctly raises bson.errors.InvalidStringData (PYTHON-3048).
Fixed a bug that caused AutoReconnect("connection pool paused") errors in the child process after fork (PYTHON-3257).
Fixed a bug where ~pymongo.collection.Collection.count_documents and ~pymongo.collection.Collection.distinct would fail in a transaction with directConnection=True (PYTHON-3333).
GridFS no longer uploads an incomplete files collection document after encountering an error in the middle of an upload fork. This results in fewer ~gridfs.errors.CorruptGridFile errors (PYTHON-1552).
Renamed PyMongo's internal C extension methods to avoid crashing due to name conflicts with mpi4py and other shared libraries (PYTHON-2110).
Fixed tight CPU loop for network I/O when using PyOpenSSL (PYTHON-3187).
pymongocrypt 1.3.0 or later is now required for client side field level encryption support.
~pymongo.collection.Collection.estimated_document_count now always uses the count command. Due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command was not included in V1 of the Stable API. Users of the Stable API with estimated_document_count are recommended to upgrade their server version to 5.0.9+ or set pymongo.server_api.ServerApi.strict to False to avoid encountering errors (PYTHON-3167).
Removed generic typing from ~pymongo.client_session.ClientSession to improve support for Pyright (PYTHON-3283).
Added __all__ to the bson, pymongo, and gridfs packages. This could be a breaking change for apps that relied on from bson import * to import APIs not present in __all__ (PYTHON-3311).
See the PyMongo 4.2 release notes in JIRA for the list of resolved issues in this release.
Version 4.1.1 fixes a number of bugs:
Version 4.1.1 fixes a number of bugs:
Fixed a memory leak bug when calling ~bson.decode_all without a codec_options argument (PYTHON-3222).
Fixed a bug where ~bson.decode_all did not accept codec_options as a keyword argument (PYTHON-3222).
Fixed an oversight where type markers (py.typed files) were not included in our release distributions (PYTHON-3214).
Fixed a bug where pymongo would raise a "NameError: name sys is not defined" exception when attempting to parse a "mongodb+srv://" URI when the dnspython dependency was not installed (PYTHON-3198).
See the PyMongo 4.1.1 release notes in JIRA for the list of resolved issues in this release.
Nothing published for this version
- No changes
No changes
- No changes
No changes
PyMongo 4.0 brings a number of improvements as well as some backward breaking changes. For example, all APIs deprecated in PyMongo 3.X have been remov…
Warning
PyMongo 4.0 drops support for Python 2.7, 3.4, and 3.5.
Warning
PyMongo 4.0 drops support for MongoDB 2.6, 3.0, 3.2, and 3.4.
Warning
PyMongo 4.0 changes the default value of the directConnection URI option and keyword argument to ~pymongo.mongo_client.MongoClient to False instead of None, allowing for the automatic discovery of replica sets. This means that if you want a direct connection to a single server you must pass directConnection=True as a URI option or keyword argument. For more details, see the relevant section of the PyMongo 4.x migration guide: pymongo4-migration-direct-connection.
PyMongo 4.0 brings a number of improvements as well as some backward breaking changes. For example, all APIs deprecated in PyMongo 3.X have been removed. Be sure to read the changes listed below and the migrate-to-pymongo4 before upgrading from PyMongo 3.x.
Removed support for Python 2.7, 3.4, and 3.5. Python 3.6.2+ is now required.
The default uuid_representation for ~bson.codec_options.CodecOptions, ~bson.json_util.JSONOptions, and ~pymongo.mongo_client.MongoClient has been changed from bson.binary.UuidRepresentation.PYTHON_LEGACY to bson.binary.UuidRepresentation.UNSPECIFIED. Attempting to encode a uuid.UUID instance to BSON or JSON now produces an error by default. See UUID representations for details.
Removed the waitQueueMultiple keyword argument to ~pymongo.mongo_client.MongoClient and removed pymongo.errors.ExceededMaxWaiters.
Removed the socketKeepAlive keyword argument to ~pymongo.mongo_client.MongoClient.
Removed pymongo.mongo_client.MongoClient.fsync, pymongo.mongo_client.MongoClient.unlock, and pymongo.mongo_client.MongoClient.is_locked.
Removed pymongo.mongo_client.MongoClient.database_names.
Removed pymongo.mongo_client.MongoClient.max_bson_size.
Removed pymongo.mongo_client.MongoClient.max_message_size.
Removed pymongo.mongo_client.MongoClient.max_write_batch_size.
Removed pymongo.mongo_client.MongoClient.event_listeners.
Removed pymongo.mongo_client.MongoClient.max_pool_size.
Removed pymongo.mongo_client.MongoClient.max_idle_time_ms.
Removed pymongo.mongo_client.MongoClient.local_threshold_ms.
Removed pymongo.mongo_client.MongoClient.server_selection_timeout.
Removed pymongo.mongo_client.MongoClient.retry_writes.
Removed pymongo.mongo_client.MongoClient.retry_reads.
Removed pymongo.database.Database.eval, pymongo.database.Database.system_js and pymongo.database.SystemJS.
Removed pymongo.database.Database.collection_names.
Removed pymongo.database.Database.current_op.
Removed pymongo.database.Database.authenticate and pymongo.database.Database.logout.
Removed pymongo.database.Database.error, pymongo.database.Database.last_status, pymongo.database.Database.previous_error, pymongo.database.Database.reset_error_history.
Removed pymongo.database.Database.add_user and pymongo.database.Database.remove_user.
Removed support for database profiler helpers ~pymongo.database.Database.profiling_level, ~pymongo.database.Database.set_profiling_level, and ~pymongo.database.Database.profiling_info. Instead, users should run the `profile command`_ with the ~pymongo.database.Database.command helper directly.
Removed pymongo.OFF, pymongo.SLOW_ONLY, and pymongo.ALL.
Removed pymongo.collection.Collection.parallel_scan.
Removed pymongo.collection.Collection.ensure_index.
Removed pymongo.collection.Collection.reindex.
Removed pymongo.collection.Collection.save.
Removed pymongo.collection.Collection.insert.
Removed pymongo.collection.Collection.update.
Removed pymongo.collection.Collection.remove.
Removed pymongo.collection.Collection.find_and_modify.
Removed pymongo.collection.Collection.count.
Removed pymongo.collection.Collection.initialize_ordered_bulk_op, pymongo.collection.Collection.initialize_unordered_bulk_op, and pymongo.bulk.BulkOperationBuilder. Use pymongo.collection.Collection.bulk_write instead.
Removed pymongo.collection.Collection.group.
Removed pymongo.collection.Collection.map_reduce and pymongo.collection.Collection.inline_map_reduce.
Removed the useCursor option for ~pymongo.collection.Collection.aggregate.
Removed pymongo.mongo_client.MongoClient.close_cursor. Use pymongo.cursor.Cursor.close instead.
Removed pymongo.mongo_client.MongoClient.kill_cursors.
Removed pymongo.cursor_manager.CursorManager and pymongo.cursor_manager.
Removed pymongo.mongo_client.MongoClient.set_cursor_manager.
Removed pymongo.cursor.Cursor.count.
Removed pymongo.thread_util.
Removed ~pymongo.mongo_replica_set_client.MongoReplicaSetClient.
Removed ~pymongo.ismaster.IsMaster. Use ~pymongo.hello.Hello instead.
Removed pymongo.son_manipulator, pymongo.son_manipulator.SONManipulator, pymongo.son_manipulator.ObjectIdInjector, pymongo.son_manipulator.ObjectIdShuffler, pymongo.son_manipulator.AutoReference, pymongo.son_manipulator.NamespaceInjector, pymongo.database.Database.add_son_manipulator, pymongo.database.Database.outgoing_copying_manipulators, pymongo.database.Database.outgoing_manipulators, pymongo.database.Database.incoming_copying_manipulators, and pymongo.database.Database.incoming_manipulators.
Removed the manipulate and modifiers parameters from ~pymongo.collection.Collection.find, ~pymongo.collection.Collection.find_one, ~pymongo.collection.Collection.find_raw_batches, and ~pymongo.cursor.Cursor.
Removed pymongo.message.delete, pymongo.message.get_more, pymongo.message.insert, pymongo.message.kill_cursors, pymongo.message.query, and pymongo.message.update.
Removed pymongo.errors.NotMasterError. Use pymongo.errors.NotPrimaryError instead.
Removed pymongo.errors.CertificateError.
Removed pymongo.GEOHAYSTACK.
Removed bson.binary.UUIDLegacy.
Removed bson.json_util.STRICT_JSON_OPTIONS. Use ~bson.json_util.RELAXED_JSON_OPTIONS or ~bson.json_util.CANONICAL_JSON_OPTIONS instead.
Changed the default JSON encoding representation from legacy to relaxed. The json_mode parameter for bson.json_util.dumps now defaults to ~bson.json_util.RELAXED_JSON_OPTIONS.
Changed the BSON and JSON decoding behavior of ~bson.dbref.DBRef to match the behavior outlined in the DBRef specification version 1.0. Specifically, PyMongo now only decodes a subdocument into a ~bson.dbref.DBRef if and only if, it contains both $ref and $id fields and the $ref, $id, and $db fields are of the correct type. Otherwise the document is returned as normal. Previously, any subdocument containing a $ref field would be decoded as a ~bson.dbref.DBRef.
The "tls" install extra is no longer necessary or supported and will be ignored by pip.
The tz_aware argument to ~bson.json_util.JSONOptions now defaults to False instead of True. bson.json_util.loads now decodes datetime as naive by default. See tz_aware_default_change for more info.
directConnection URI option and keyword argument to ~pymongo.mongo_client.MongoClient defaults to False instead of None, allowing for the automatic discovery of replica sets. This means that if you want a direct connection to a single server you must pass directConnection=True as a URI option or keyword argument.
The hint option is now required when using min or max queries with ~pymongo.collection.Collection.find.
name is now a required argument for the pymongo.driver_info.DriverInfo class.
When providing a "mongodb+srv://" URI to ~pymongo.mongo_client.MongoClient constructor you can now use the srvServiceName URI option to specify your own SRV service name.
~bson.son.SON.items now returns a dict_items object rather than a list.
Removed bson.son.SON.iteritems.
~pymongo.collection.Collection and ~pymongo.database.Database now raises an error upon evaluating as a Boolean, please use the syntax if collection is not None: or if database is not None: as opposed to the previous syntax which was simply if collection: or if database:. You must now explicitly compare with None.
~pymongo.mongo_client.MongoClient cannot execute any operations after being closed. The previous behavior would simply reconnect. However, now you must create a new instance.
Classes ~bson.int64.Int64, ~bson.min_key.MinKey, ~bson.max_key.MaxKey, ~bson.timestamp.Timestamp, ~bson.regex.Regex, and ~bson.dbref.DBRef all implement __slots__ now. This means that their attributes are fixed, and new attributes cannot be added to them at runtime.
Empty projections (eg {} or []) for ~pymongo.collection.Collection.find, and ~pymongo.collection.Collection.find_one are passed to the server as-is rather than the previous behavior which substituted in a projection of {"_id": 1}. This means that an empty projection will now return the entire document, not just the "_id" field.
~pymongo.mongo_client.MongoClient now raises a ~pymongo.errors.ConfigurationError when more than one URI is passed into the hosts argument.
~pymongo.mongo_client.MongoClient` now raises an ~pymongo.errors.InvalidURI exception when it encounters unescaped percent signs in username and password when parsing MongoDB URIs.
Comparing two ~pymongo.mongo_client.MongoClient instances now uses a set of immutable properties rather than ~pymongo.mongo_client.MongoClient.address which can change.
Removed the disable_md5 parameter for ~gridfs.GridFSBucket and ~gridfs.GridFS. See removed-gridfs-checksum for details.
pymongocrypt 1.2.0 or later is now required for client side field level encryption support.
Enhanced connection pooling to create connections more efficiently and avoid connection storms.
Added the maxConnecting URI and ~pymongo.mongo_client.MongoClient keyword argument.
~pymongo.mongo_client.MongoClient now accepts a URI and keyword argument srvMaxHosts that limits the number of mongos-like hosts a client will connect to. More specifically, when a mongodb+srv:// connection string resolves to more than srvMaxHosts number of hosts, the client will randomly choose a srvMaxHosts sized subset of hosts.
Added pymongo.mongo_client.MongoClient.options for read-only access to a client's configuration options.
Support for the "kmip" KMS provider for client side field level encryption. See the docstring for ~pymongo.encryption_options.AutoEncryptionOpts and ~pymongo.encryption.
See the PyMongo 4.0 release notes in JIRA for the list of resolved issues in this release.
Deprecated ~pymongo.collection.Collection.map_reduce and ~pymongo.collection.Collection.inline_map_reduce. Use ~pymongo.collection.Collection.aggregat…
Version 3.13 provides an upgrade path to PyMongo 4.x. Most of the API changes from PyMongo 4.0 have been backported in a backward compatible way, allowing applications to be written against PyMongo >= 3.13, rather then PyMongo 3.x or PyMongo 4.x. See the PyMongo 4 Migration Guide for detailed examples.
Added pymongo.mongo_client.MongoClient.options for read-only access to a client's configuration options.
PyMongo 3.13 drops support for Python 3.4.
Fixed a memory leak bug when calling ~bson.decode_all without a codec_options argument (PYTHON-3222).
Fixed a bug where ~bson.decode_all did not accept codec_options as a keyword argument (PYTHON-3222).
Deprecated ~pymongo.collection.Collection.map_reduce and ~pymongo.collection.Collection.inline_map_reduce. Use ~pymongo.collection.Collection.aggregate instead.
Deprecated pymongo.mongo_client.MongoClient.event_listeners. Use ~pymongo.mongo_client.options.event_listeners instead.
Deprecated pymongo.mongo_client.MongoClient.max_pool_size. Use ~pymongo.mongo_client.options.pool_options.max_pool_size instead.
Deprecated pymongo.mongo_client.MongoClient.max_idle_time_ms. Use ~pymongo.mongo_client.options.pool_options.max_idle_time_seconds instead.
Deprecated pymongo.mongo_client.MongoClient.local_threshold_ms. Use ~pymongo.mongo_client.options.local_threshold_ms instead.
Deprecated pymongo.mongo_client.MongoClient.server_selection_timeout. Use ~pymongo.mongo_client.options.server_selection_timeout instead.
Deprecated pymongo.mongo_client.MongoClient.retry_writes. Use ~pymongo.mongo_client.options.retry_writes instead.
Deprecated pymongo.mongo_client.MongoClient.retry_reads. Use ~pymongo.mongo_client.options.retry_reads instead.
Deprecated pymongo.mongo_client.MongoClient.max_bson_size, pymongo.mongo_client.MongoClient.max_message_size, and pymongo.mongo_client.MongoClient.max_write_batch_size. These helpers were incorrect when in loadBalanced=true mode and ambiguous in clusters with mixed versions. Use the hello command to get the authoritative value from the remote server instead. Code like this:
max_bson_size = client.max_bson_size max_message_size = client.max_message_size max_write_batch_size = client.max_write_batch_size
can be changed to this:
doc = client.admin.command('hello')
max_bson_size = doc['maxBsonObjectSize']
max_message_size = doc['maxMessageSizeBytes']
max_write_batch_size = doc['maxWriteBatchSize']
See the PyMongo 3.13.0 release notes in JIRA for the list of resolved issues in this release.
Issues Resolved ...............
Version 3.12.3 fixes a bug that prevented bson.json_util.loads from decoding a document with a non-string "$regex" field (PYTHON-3028).
See the PyMongo 3.12.3 release notes in JIRA for the list of resolved issues in this release.
Issues Resolved ...............
Version 3.12.2 fixes a number of bugs:
Fixed a bug that prevented PyMongo from retrying bulk writes after a writeConcernError on MongoDB 4.4+ (PYTHON-2984).
Fixed a bug that could cause the driver to hang during automatic client side field level encryption (PYTHON-3017).
See the PyMongo 3.12.2 release notes in JIRA for the list of resolved issues in this release.
Issues Resolved ...............
Version 3.12.1 fixes a number of bugs:
Fixed a bug that caused a multi-document transaction to fail when the first operation was large bulk write (>48MB) that required splitting a batched write command (PYTHON-2915).
Fixed a bug that caused the tlsDisableOCSPEndpointCheck URI option to be applied incorrectly (PYTHON-2866).
See the PyMongo 3.12.1 release notes in JIRA for the list of resolved issues in this release.
.. warning:: PyMongo 3.12.0 deprecates support for Python 2.7, 3.4 and 3.5. These Python versions will not be supported by PyMongo 4.
Warning
PyMongo 3.12.0 deprecates support for Python 2.7, 3.4 and 3.5. These Python versions will not be supported by PyMongo 4.
Warning
PyMongo now allows insertion of documents with keys that include dots ('.') or start with dollar signs ('$').
pymongocrypt 1.1.0 or later is now required for client side field level encryption support.
Iterating over gridfs.grid_file.GridOut now moves through the file line by line instead of chunk by chunk, and does not restart at the top for subsequent iterations on the same object. Call seek(0) to reset the iterator.
Added support for MongoDB 5.0.
Support for MongoDB Stable API, see ~pymongo.server_api.ServerApi.
Support for snapshot reads on secondaries (see snapshot reads).
Support for Azure and GCP KMS providers for client side field level encryption. See the docstring for ~pymongo.mongo_client.MongoClient, ~pymongo.encryption_options.AutoEncryptionOpts, and ~pymongo.encryption.
Support AWS authentication with temporary credentials when connecting to KMS in client side field level encryption.
Support for connecting to load balanced MongoDB clusters via the new loadBalanced URI option.
Support for creating timeseries collections via the timeseries and expireAfterSeconds arguments to ~pymongo.database.Database.create_collection.
Added pymongo.mongo_client.MongoClient.topology_description.
Added hash support to ~pymongo.mongo_client.MongoClient, ~pymongo.database.Database and ~pymongo.collection.Collection (PYTHON-2466).
Improved the error message returned by ~pymongo.collection.Collection.insert_many when supplied with an argument of incorrect type (PYTHON-1690).
Added session and read concern support to ~pymongo.collection.Collection.find_raw_batches and ~pymongo.collection.Collection.aggregate_raw_batches.
Fixed a bug that could cause the driver to deadlock during automatic client side field level encryption (PYTHON-2472).
Fixed a potential deadlock when garbage collecting an unclosed exhaust ~pymongo.cursor.Cursor.
Fixed an bug where using gevent.Timeout to timeout an operation could lead to a deadlock.
Fixed the following bug with Atlas Data Lake. When closing cursors, pymongo now sends killCursors with the namespace returned the cursor's initial command response.
Fixed a bug in ~pymongo.cursor.RawBatchCursor that caused it to return an empty bytestring when the cursor contained no results. It now raises StopIteration instead.
Deprecated support for Python 2.7, 3.4 and 3.5.
Deprecated support for database profiler helpers ~pymongo.database.Database.profiling_level, ~pymongo.database.Database.set_profiling_level, and ~pymongo.database.Database.profiling_info. Instead, users should run the profile command with the ~pymongo.database.Database.command helper directly.
Deprecated ~pymongo.errors.NotMasterError. Users should use ~pymongo.errors.NotPrimaryError instead.
Deprecated ~pymongo.ismaster.IsMaster and ~pymongo.ismaster which will be removed in PyMongo 4.0 and are replaced by ~pymongo.hello.Hello and ~pymongo.hello which provide the same API.
Deprecated the pymongo.messeage module.
Deprecated the ssl_keyfile and ssl_certfile URI options in favor of tlsCertificateKeyFile (see TLS).
See the PyMongo 3.12.0 release notes in JIRA for the list of resolved issues in this release.
Nothing published for this version
Issues Resolved ...............
Version 3.11.3 fixes a bug that prevented PyMongo from retrying writes after a writeConcernError on MongoDB 4.4+ (PYTHON-2452)
See the PyMongo 3.11.3 release notes in JIRA for the list of resolved issues in this release.
Issues Resolved ...............
Version 3.11.2 includes a number of bugfixes. Highlights include:
Fixed a memory leak caused by failing SDAM monitor checks on Python 3 (PYTHON-2433).
Fixed a regression that changed the string representation of ~pymongo.errors.BulkWriteError (PYTHON-2438).
Fixed a bug that made it impossible to use bson.codec_options.CodecOptions.with_options and ~bson.json_util.JSONOptions.with_options on some early versions of Python 3.4 and Python 3.5 due to a bug in the standard library implementation of collections.namedtuple._asdict (PYTHON-2440).
Fixed a bug that resulted in a TypeError exception when a PyOpenSSL socket was configured with a timeout of None (PYTHON-2443).
See the PyMongo 3.11.2 release notes in JIRA for the list of resolved issues in this release.
…and ~pymongo.encryption. Note: Backwards-breaking changes may be made before the final release.
Version 3.11.1 adds support for Python 3.9 and includes a number of bugfixes. Highlights include:
Support for Python 3.9.
Initial support for Azure and GCP KMS providers for client side field level encryption is in beta. See the docstring for ~pymongo.mongo_client.MongoClient, ~pymongo.encryption_options.AutoEncryptionOpts, and ~pymongo.encryption. Note: Backwards-breaking changes may be made before the final release.
Fixed a bug where the bson.json_util.JSONOptions API did not match the bson.codec_options.CodecOptions API due to the absence of a bson.json_util.JSONOptions.with_options method. This method has now been added.
Fixed a bug which made it impossible to serialize ~pymongo.errors.BulkWriteError instances using pickle.
Fixed a bug wherein PyMongo did not always discard an implicit session after encountering a network error.
Fixed a bug where connections created in the background were not authenticated.
Fixed a memory leak in the bson module when using a ~bson.codec_options.TypeRegistry.
See the PyMongo 3.11.1 release notes in JIRA for the list of resolved issues in this release.
Your coding agent can read these notes before it upgrades. Set up the MCP server →