Changelog - PyMongo 4.15.5 documentation (original) (raw)

Changes in Version 4.15.5 (2025/12/02)

Version 4.15.5 is a bug fix release.

Issues Resolved

See the PyMongo 4.15.5 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.15.4 (2025/10/21)

Version 4.15.4 is a bug fix release.

Issues Resolved

See the PyMongo 4.15.4 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.15.3 (2025/10/07)

Version 4.15.3 is a bug fix release.

Issues Resolved

See the PyMongo 4.15.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.15.2 (2025/10/01)

Version 4.15.2 is a bug fix release.

Issues Resolved

See the PyMongo 4.15.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.15.1 (2025/09/16)

Version 4.15.1 is a bug fix release.

Issues Resolved

See the PyMongo 4.15.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.15.0 (2025/09/10)

PyMongo 4.15 brings a number of changes including:

Changes in Version 4.14.1 (2025/08/19)

Version 4.14.1 is a bug fix release.

Issues Resolved

See the PyMongo 4.14.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.14.0 (2025/08/06)

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:

Issues Resolved

See the PyMongo 4.14 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.13.2 (2025/06/17)

Version 4.13.2 is a bug fix release.

Issues Resolved

See the PyMongo 4.13.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.13.1 (2025/06/10)

Version 4.13.1 is a bug fix release.

Issues Resolved

See the PyMongo 4.13.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.13.0 (2025/05/14)

PyMongo 4.13 brings a number of changes including:

Issues Resolved

See the PyMongo 4.13 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.12.1 (2025/04/29)

Version 4.12.1 is a bug fix release.

Issues Resolved

See the PyMongo 4.12.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.12.0 (2025/04/08)

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:

Issues Resolved

See the PyMongo 4.12 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.11.2 (2025/03/05)

Version 4.11.2 is a bug fix release.

Issues Resolved

See the PyMongo 4.11.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.11.1 (2025/02/10)

Changes in Version 4.11.0 (2025/01/28)

Warning

PyMongo 4.11 drops support for Python 3.8 and PyPy 3.9: Python 3.9+ or PyPy 3.10+ is now required.

Warning

PyMongo 4.11 drops support for MongoDB 3.6. PyMongo now supports MongoDB 4.0+. Driver support for MongoDB 3.6 reached end of life in April 2024.

Warning

Driver support for MongoDB 4.0 reaches end of life in April 2025. A future minor release of PyMongo will raise the minimum supported MongoDB Server version from 4.0 to 4.2. This is in accordance with [MongoDB Software Lifecycle Schedules](https://www.mongodb.com/legal/support-policy/lifecycles).Support for MongoDB Server 4.0 will be dropped in a future release!

Warning

This version does not include wheels for ppc64le or s390x architectures, see PYTHON-5058 for more information.

PyMongo 4.11 brings a number of changes including:

Issues Resolved

See the PyMongo 4.11 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.10.1 (2024/10/01)

Version 4.10.1 is a bug fix release.

Issues Resolved

See the PyMongo 4.10.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.10.0 (2024/09/30)

Issues Resolved

See the PyMongo 4.10 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.9.2 (2024/10/02)

Issues Resolved

See the PyMongo 4.9.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.9.1 (2024/09/18)

Issues Resolved

See the PyMongo 4.9.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.9 (2024/09/18)

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:

Call MongoClient.close() to safely shut down your client and free up resources.

Issues Resolved

See the PyMongo 4.9 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.8.0 (2024/06/26)

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:

Unavoidable breaking changes

Issues Resolved

See the PyMongo 4.8 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.7.3 (2024/06/04)

Version 4.7.3 has further fixes for lazily loading modules.

Issues Resolved

See the PyMongo 4.7.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.7.2 (2024/05/07)

Version 4.7.2 fixes a bug introduced in 4.7.0:

Issues Resolved

See the PyMongo 4.7.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.7.1 (2024/04/30)

Version 4.7.1 fixes a bug introduced in 4.7.0:

Issues Resolved

See the PyMongo 4.7.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.7.0 (2024/04/24)

PyMongo 4.7 brings a number of improvements including:

Warning

PyMongo depends on dnspython, which released version 2.6.1 with a fix forCVE-2023-29483. We do not explicitly require that version, but we strongly recommend that you install at least that version in your environment.

Unavoidable breaking changes

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')])

Changes in Version 4.6.3 (2024/03/27)

PyMongo 4.6.3 fixes the following bug:

Issues Resolved

See the PyMongo 4.6.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.6.2 (2024/02/21)

PyMongo 4.6.2 fixes the following bug:

Issues Resolved

See the PyMongo 4.6.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.6.1 (2023/11/29)

PyMongo 4.6.1 fixes the following bug:

Issues Resolved

See the PyMongo 4.6.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.6.0 (2023/11/01)

PyMongo 4.6 brings a number of improvements including:

Issues Resolved

See the PyMongo 4.6 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.5.0 (2023/08/22)

PyMongo 4.5 brings a number of improvements including:

Warning

PyMongo no longer supports PyPy3 versions older than 3.8. Users must upgrade to PyPy3.8+.

Issues Resolved

See the PyMongo 4.5 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.4.1 (2023/07/13)

Version 4.4.1 fixes the following bugs:

Issues Resolved

See the PyMongo 4.4.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.4.0 (2023/06/21)

PyMongo 4.4 brings a number of improvements including:

Issues Resolved

See the PyMongo 4.4 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.3.3 (2022/11/17)

Version 4.3.3 documents support for the following:

Bug Fixes

Issues Resolved

See the PyMongo 4.3.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.3.2 (2022/10/18)

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:

Bug fixes

Issues Resolved

See the PyMongo 4.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.2.0 (2022/07/20)

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:

Bug fixes

Unavoidable breaking changes

Issues Resolved

See the PyMongo 4.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.1.1 (2022/04/13)

Version 4.1.1 fixes a number of bugs:

Issues Resolved

See the PyMongo 4.1.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.1 (2021/12/07)

Warning

PyMongo 4.1 drops support for Python 3.6.0 and 3.6.1, Python 3.6.2+ is now required.

PyMongo 4.1 brings a number of improvements including:

Bug fixes

Issues Resolved

See the PyMongo 4.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 4.0.2 (2022/03/03)

Changes in Version 4.0.1 (2021/12/07)

Changes in Version 4.0 (2021/11/29)

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 MongoClientto 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 passdirectConnection=True as a URI option or keyword argument. For more details, see the relevant section of the PyMongo 4.x migration guide: directConnection defaults to False.

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 PyMongo 4 Migration Guidebefore upgrading from PyMongo 3.x.

Breaking Changes in 4.0

Notable improvements

Issues Resolved

See the PyMongo 4.0 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.13.0 (2022/11/01)

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.

Notable improvements

Issues Resolved

PyMongo 3.13 drops support for Python 3.4.

Bug fixes

Deprecations

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.

Changes in Version 3.12.3 (2021/12/07)

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.

Changes in Version 3.12.2 (2021/11/29)

Issues Resolved

Version 3.12.2 fixes a number of bugs:

See the PyMongo 3.12.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.12.1 (2021/10/19)

Issues Resolved

Version 3.12.1 fixes a number of bugs:

See the PyMongo 3.12.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.12.0 (2021/07/13)

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 (‘$’).

Notable improvements

Bug fixes

Deprecations

Issues Resolved

See the PyMongo 3.12.0 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.11.3 (2021/02/02)

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.

Changes in Version 3.11.2 (2020/12/02)

Issues Resolved

Version 3.11.2 includes a number of bugfixes. Highlights include:

See the PyMongo 3.11.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.11.1 (2020/11/17)

Version 3.11.1 adds support for Python 3.9 and includes a number of bugfixes. Highlights include:

Issues Resolved

See the PyMongo 3.11.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.11.0 (2020/07/30)

Version 3.11 adds support for MongoDB 4.4 and includes a number of bug fixes. Highlights include:

Deprecations:

Unavoidable breaking changes:

Issues Resolved

See the PyMongo 3.11.0 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.10.1 (2020/01/07)

Version 3.10.1 fixes the following issues discovered since the release of 3.10.0:

Issues Resolved

See the PyMongo 3.10.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.10.0 (2019/12/10)

Version 3.10 includes a number of improvements and bug fixes. Highlights include:

Issues Resolved

See the PyMongo 3.10 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.9.0 (2019/08/13)

Version 3.9 adds support for MongoDB 4.2. Highlights include:

Unavoidable breaking changes:

Issues Resolved

See the PyMongo 3.9 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.8.0 (2019/04/22)

Warning

PyMongo no longer supports Python 2.6. RHEL 6 users should install Python 2.7 or newer from Red Hat Software Collections. CentOS 6 users should install Python 2.7 or newer from SCL

Warning

PyMongo no longer supports PyPy3 versions older than 3.5. Users must upgrade to PyPy3.5+.

Unavoidable breaking changes:

Issues Resolved

See the PyMongo 3.8 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.7.2 (2018/10/10)

Version 3.7.2 fixes a few issues discovered since the release of 3.7.1.

Issues Resolved

See the PyMongo 3.7.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.7.1 (2018/07/16)

Version 3.7.1 fixes a few issues discovered since the release of 3.7.0.

Issues Resolved

See the PyMongo 3.7.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.7.0 (2018/06/26)

Version 3.7 adds support for MongoDB 4.0. Highlights include:

Deprecations:

Unavoidable breaking changes:

Issues Resolved

See the PyMongo 3.7 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.6.1 (2018/03/01)

Version 3.6.1 fixes bugs reported since the release of 3.6.0:

Issues Resolved

See the PyMongo 3.6.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.6.0 (2017/08/23)

Version 3.6 adds support for MongoDB 3.6, drops support for CPython 3.3 (PyPy3 is still supported), and drops support for MongoDB versions older than 2.6. If connecting to a MongoDB 2.4 server or older, PyMongo now throws aConfigurationError.

Highlights include:

Deprecations:

Unavoidable breaking changes:

Issues Resolved

See the PyMongo 3.6 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.5.1 (2017/08/23)

Version 3.5.1 fixes bugs reported since the release of 3.5.0:

Issues Resolved

See the PyMongo 3.5.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.5.0 (2017/08/08)

Version 3.5 implements a number of improvements and bug fixes:

Highlights include:

Changes and Deprecations:

Issues Resolved

See the PyMongo 3.5 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.4.0 (2016/11/29)

Version 3.4 implements the new server features introduced in MongoDB 3.4 and a whole lot more:

Highlights include:

Warning

Starting in PyMongo 3.4, bson.code.Code.scope may returnNone, as the default scope is None instead of {}.

Note

PyMongo 3.4+ attempts to create sockets non-inheritable when possible (i.e. it sets the close-on-exec flag on socket file descriptors). Support is limited to a subset of POSIX operating systems (not including Windows) and the flag usually cannot be set in a single atomic operation. CPython 3.4+ implements PEP 446, creating all file descriptors non-inheritable by default. Users that require this behavior are encouraged to upgrade to CPython 3.4+.

Since 3.4rc0, the max staleness option has been renamed from maxStalenessMSto maxStalenessSeconds, its smallest value has changed from twiceheartbeatFrequencyMS to 90 seconds, and its default value has changed fromNone or 0 to -1.

Issues Resolved

See the PyMongo 3.4 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.3.1 (2016/10/27)

Version 3.3.1 fixes a memory leak when decoding elements inside of aRawBSONDocument.

Issues Resolved

See the PyMongo 3.3.1 release notes in Jira for the list of resolved issues in this release.

Changes in Version 3.3.0 (2016/07/12)

Version 3.3 adds the following major new features:

Warning

PyMongo 3.3 drops support for MongoDB versions older than 2.4. It also drops support for python 3.2 (pypy3 continues to be supported).

Issues Resolved

See the PyMongo 3.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.2.2 (2016/03/15)

Version 3.2.2 fixes a few issues reported since the release of 3.2.1, including a fix for using the connect option in the MongoDB URI and support for setting the batch size for a query to 1 when using MongoDB 3.2+.

Issues Resolved

See the PyMongo 3.2.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.2.1 (2016/02/02)

Version 3.2.1 fixes a few issues reported since the release of 3.2, including running the mapreduce command twice when calling theinline_map_reduce() method and aTypeError being raised when callingdownload_to_stream(). This release also improves error messaging around BSON decoding.

Issues Resolved

See the PyMongo 3.2.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.2 (2015/12/07)

Version 3.2 implements the new server features introduced in MongoDB 3.2.

Highlights include:

Issues Resolved

See the PyMongo 3.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.1.1 (2015/11/17)

Version 3.1.1 fixes a few issues reported since the release of 3.1, including a regression in error handling for oversize command documents and interrupt handling issues in the C extensions.

Issues Resolved

See the PyMongo 3.1.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.1 (2015/11/02)

Version 3.1 implements a few new features and fixes bugs reported since the release of 3.0.3.

Highlights include:

Changes in internal classes

The private PeriodicExecutor class no longer takes a condition_classoption, and the private thread_util.Event class is removed.

Issues Resolved

See the PyMongo 3.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.0.3 (2015/06/30)

Version 3.0.3 fixes issues reported since the release of 3.0.2, including a feature breaking bug in the GSSAPI implementation.

Issues Resolved

See the PyMongo 3.0.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.0.2 (2015/05/12)

Version 3.0.2 fixes issues reported since the release of 3.0.1, most importantly a bug that could route operations to replica set members that are not in primary or secondary state when usingPrimaryPreferred orNearest. It is a recommended upgrade for all users of PyMongo 3.0.x.

Issues Resolved

See the PyMongo 3.0.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.0.1 (2015/04/21)

Version 3.0.1 fixes issues reported since the release of 3.0, most importantly a bug in GridFS.delete that could prevent file chunks from actually being deleted.

Issues Resolved

See the PyMongo 3.0.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 3.0 (2015/04/07)

PyMongo 3.0 is a partial rewrite of PyMongo bringing a large number of improvements:

PyMongo 3.0 brings a large number of API changes. Be sure to read the changes listed below before upgrading from PyMongo 2.x.

Warning

PyMongo no longer supports Python 2.4, 2.5, or 3.1. If you must use PyMongo with these versions of Python the 2.x branch of PyMongo will be minimally supported for some time.

SONManipulator changes

The SONManipulator API has limitations as a technique for transforming your data. Instead, it is more flexible and straightforward to transform outgoing documents in your own code before passing them to PyMongo, and transform incoming documents after receiving them from PyMongo.

Thus the add_son_manipulator() method is deprecated. PyMongo 3’s new CRUD API does not apply SON manipulators to documents passed to bulk_write(),insert_one(),insert_many(),update_one(), orupdate_many(). SON manipulators are notapplied to documents returned by the new methodsfind_one_and_delete(),find_one_and_replace(), andfind_one_and_update().

SSL/TLS changes

When ssl is True the ssl_cert_reqs option now defaults tossl.CERT_REQUIRED if not provided. PyMongo will attempt to load OS provided CA certificates to verify the server, raisingConfigurationError if it cannot.

Gevent Support

In previous versions, PyMongo supported Gevent in two modes: you could callgevent.monkey.patch_socket() and pass use_greenlets=True toMongoClient, or you could simply callgevent.monkey.patch_all() and omit the use_greenlets argument.

In PyMongo 3.0, the use_greenlets option is gone. To use PyMongo with Gevent simply call gevent.monkey.patch_all().

For more information, see Gevent.

MongoClient changes

MongoClient is now the one and only client class for a standalone server, mongos, or replica set. It includes the functionality that had been split intoMongoReplicaSetClient: it can connect to a replica set, discover all its members, and monitor the set for stepdowns, elections, and reconfigs.MongoClient now also supports the fullReadPreference API.

The obsolete classes MasterSlaveConnection, Connection, andReplicaSetConnection are removed.

The MongoClient constructor no longer blocks while connecting to the server or servers, and it no longer raises ConnectionFailure if they are unavailable, nor ConfigurationErrorif the user’s credentials are wrong. Instead, the constructor returns immediately and launches the connection process on background threads. The connect option is added to control whether these threads are started immediately, or when the client is first used.

Therefore the alive method is removed since it no longer provides meaningful information; even if the client is disconnected, it may discover a server in time to fulfill the next operation.

In PyMongo 2.x, MongoClient accepted a list of standalone MongoDB servers and used the first it could connect to:

MongoClient(['host1.com:27017', 'host2.com:27017'])

A list of multiple standalones is no longer supported; if multiple servers are listed they must be members of the same replica set, or mongoses in the same sharded cluster.

The behavior for a list of mongoses is changed from “high availability” to “load balancing”. Before, the client connected to the lowest-latency mongos in the list, and used it until a network error prompted it to re-evaluate all mongoses’ latencies and reconnect to one of them. In PyMongo 3, the client monitors its network latency to all the mongoses continuously, and distributes operations evenly among those with the lowest latency. See load balancing for more information.

The client methods start_request, in_request, and end_requestare removed, and so is the auto_start_request option. Requests were designed to make read-your-writes consistency more likely with the w=0write concern. Additionally, a thread in a request used the same member for all secondary reads in a replica set. To ensure read-your-writes consistency in PyMongo 3.0, do not override the default write concern with w=0, and do not override the default read preference of PRIMARY.

Support for the slaveOk (or slave_okay), safe, andnetwork_timeout options has been removed. UseSECONDARY_PREFERRED instead of slave_okay. Accept the default write concern, acknowledged writes, instead of setting safe=True. Use socketTimeoutMS in place of network_timeout (note that network_timeout was in seconds, where as socketTimeoutMS is milliseconds).

The max_pool_size option has been removed. It is replaced by themaxPoolSize MongoDB URI option. maxPoolSize is now a supported URI option in PyMongo and can be passed as a keyword argument.

The copy_database method is removed, see Copy and Clone Databases for alternatives.

The disconnect method is removed. Useclose() instead.

The get_document_class method is removed. Usecodec_options instead.

The get_lasterror_options, set_lasterror_options, andunset_lasterror_options methods are removed. Write concern options can be passed to MongoClient as keyword arguments or MongoDB URI options.

The get_database() method is added for getting a Database instance with its options configured differently than the MongoClient’s.

The following read-only attributes have been added:

The following attributes are now read-only:

The following attributes have been removed:

The following attributes have been renamed:

Cursor changes

The conn_id property is renamed to address.

Cursor management changes

CursorManager andset_cursor_manager() are no longer deprecated. If you subclass CursorManageryour implementation of close()must now take a second parameter, address. The BatchCursorManager class is removed.

The second parameter to close_cursor()is renamed from _conn_id to address.kill_cursors() now accepts an addressparameter.

Database changes

The connection property is renamed toclient.

The following read-only attributes have been added:

The following attributes are now read-only:

Use get_database() for getting a Database instance with its options configured differently than the MongoClient’s.

The following attributes have been removed:

The following methods have been added:

The following methods have been changed:

The following methods have been deprecated:

The following methods have been removed:

The get_lasterror_options, set_lasterror_options, andunset_lasterror_options methods have been removed. UseWriteConcern withget_database() instead.

Collection changes

The following read-only attributes have been added:

The following attributes are now read-only:

Use get_collection() orwith_options() for getting a Collection instance with its options configured differently than the Database’s.

The following attributes have been removed:

The following methods have been added:

The following methods have changed:

The following methods are deprecated:

The following methods have been removed:

The get_lasterror_options, set_lasterror_options, andunset_lasterror_options methods have been removed. UseWriteConcern withwith_options() instead.

Changes to find() and find_one()

The following find/find_one options have been renamed:

These renames only affect your code if you passed these as keyword arguments, like find(fields=[‘fieldname’]). If you passed only positional parameters these changes are not significant for your application.

The following find/find_one options have been added:

The following find/find_one options have been removed:

The following find/find_one options are deprecated:

The following renames need special handling.

errors changes

The exception classes UnsupportedOption and TimeoutError are deleted.

gridfs changes

Since PyMongo 1.6, methods open and close of GridFSraised an UnsupportedAPI exception, as did the entire GridFile class. The unsupported methods, the class, and the exception are all deleted.

bson changes

The compile_re option is removed from all methods that accepted it in bson and json_util. Additionally, it is removed from find(),find_one(),aggregate(),command(), and so on. PyMongo now always represents BSON regular expressions asRegex objects. This prevents errors for incompatible patterns, see PYTHON-500. Use try_compile() to attempt to convert from a BSON regular expression to a Python regular expression object.

PyMongo now decodes the int64 BSON type to Int64, a trivial wrapper around long (in python 2.x) or int (in python 3.x). This allows BSON int64 to be round tripped without losing type information in python 3. Note that if you store a python long (or a python int larger than 4 bytes) it will be returned from PyMongo as Int64.

The as_class, tz_aware, and uuid_subtype options are removed from all BSON encoding and decoding methods. UseCodecOptions to configure these options. The APIs affected are:

This is a breaking change for any application that uses the BSON API directly and changes any of the named parameter defaults. No changes are required for applications that use the default values for these options. The behavior remains the same.

Issues Resolved

See the PyMongo 3.0 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.9.5 (2017/06/30)

Version 2.9.5 works around ssl module deprecations in Python 3.6, and expected future ssl module deprecations. It also fixes bugs found since the release of 2.9.4.

Issues Resolved

See the PyMongo 2.9.5 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.9.4 (2016/09/30)

Version 2.9.4 fixes issues reported since the release of 2.9.3.

Issues Resolved

See the PyMongo 2.9.4 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.9.3 (2016/03/15)

Version 2.9.3 fixes a few issues reported since the release of 2.9.2 including thread safety issues in ensure_index(),drop_index(), anddrop_indexes().

Issues Resolved

See the PyMongo 2.9.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.9.2 (2016/02/16)

Version 2.9.2 restores Python 3.1 support, which was broken in PyMongo 2.8. It improves an error message when decoding BSON as well as fixes a couple other issues including aggregate() ignoringcodec_options andcommand() raising a superfluousDeprecationWarning.

Issues Resolved

See the PyMongo 2.9.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.9.1 (2015/11/17)

Version 2.9.1 fixes two interrupt handling issues in the C extensions and adapts a test case for a behavior change in MongoDB 3.2.

Issues Resolved

See the PyMongo 2.9.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.9 (2015/09/30)

Version 2.9 provides an upgrade path to PyMongo 3.x. Most of the API changes from PyMongo 3.0 have been backported in a backward compatible way, allowing applications to be written against PyMongo >= 2.9, rather then PyMongo 2.x or PyMongo 3.x. See the PyMongo 3 Migration Guide for detailed examples.

Note

There are a number of new deprecations in this release for features that were removed in PyMongo 3.0.

MongoClient:

MongoReplicaSetClient:

Database:

Collection:

Warning

In previous versions of PyMongo, changing the value ofdocument_class changed the behavior of all existing instances ofCollection:

coll = client.test.test coll.find_one() {u'_id': ObjectId('5579dc7cfba5220cc14d9a18')} from bson.son import SON client.document_class = SON coll.find_one() SON([(u'_id', ObjectId('5579dc7cfba5220cc14d9a18'))])

The document_class setting is now configurable at the client, database, collection, and per-operation level. This required breaking the existing behavior. To change the document class per operation in a forward compatible way usewith_options():

coll.find_one() {u'_id': ObjectId('5579dc7cfba5220cc14d9a18')} from bson.codec_options import CodecOptions coll.with_options(CodecOptions(SON)).find_one() SON([(u'_id', ObjectId('5579dc7cfba5220cc14d9a18'))])

Issues Resolved

See the PyMongo 2.9 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.8.1 (2015/05/11)

Version 2.8.1 fixes a number of issues reported since the release of PyMongo 2.8. It is a recommended upgrade for all users of PyMongo 2.x.

Issues Resolved

See the PyMongo 2.8.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.8 (2015/01/28)

Version 2.8 is a major release that provides full support for MongoDB 3.0 and fixes a number of bugs.

Special thanks to Don Mitchell, Ximing, Can Zhang, Sergey Azovskov, and Heewa Barfchin for their contributions to this release.

Highlights include:

Note

There are a number of deprecations in this release for features that will be removed in PyMongo 3.0. These include:

The JSON format for Timestamp has changed from ‘{“t”: , “i”: }’ to ‘{“$timestamp”: {“t”: , “i”: }}’. This new format will be decoded to an instance ofTimestamp. The old format will continue to be decoded to a python dict as before. Encoding to the old format is no longer supported as it was never correct and loses type information.

Issues Resolved

See the PyMongo 2.8 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.7.2 (2014/07/29)

Version 2.7.2 includes fixes for upsert reporting in the bulk API for MongoDB versions previous to 2.6, a regression in how son manipulators are applied ininsert(), a few obscure connection pool semaphore leaks, and a few other minor issues. See the list of issues resolved for full details.

Issues Resolved

See the PyMongo 2.7.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.7.1 (2014/05/23)

Version 2.7.1 fixes a number of issues reported since the release of 2.7, most importantly a fix for creating indexes and manipulating users through mongos versions older than 2.4.0.

Issues Resolved

See the PyMongo 2.7.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.7 (2014/04/03)

PyMongo 2.7 is a major release with a large number of new features and bug fixes. Highlights include:

Breaking changes

Version 2.7 drops support for replica sets running MongoDB versions older than 1.6.2.

Issues Resolved

See the PyMongo 2.7 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.6.3 (2013/10/11)

Version 2.6.3 fixes issues reported since the release of 2.6.2, most importantly a semaphore leak when a connection to the server fails.

Issues Resolved

See the PyMongo 2.6.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.6.2 (2013/09/06)

Version 2.6.2 fixes a TypeError problem when max_pool_size=None is used in Python 3.

Issues Resolved

See the PyMongo 2.6.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.6.1 (2013/09/03)

Version 2.6.1 fixes a reference leak in the insert() method.

Issues Resolved

See the PyMongo 2.6.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.6 (2013/08/19)

Version 2.6 includes some frequently requested improvements and adds support for some early MongoDB 2.6 features.

Special thanks go to Justin Patrin for his work on the connection pool in this release.

Important new features:

Warning

SIGNIFICANT BEHAVIOR CHANGE in 2.6. Previously, max_pool_sizewould limit only the idle sockets the pool would hold onto, not the number of open sockets. The default has also changed, from 10 to 100. If you pass a value for max_pool_size make sure it is large enough for the expected load. (Sockets are only opened when needed, so there is no cost to having a max_pool_size larger than necessary. Err towards a larger value.) If your application accepts the default, continue to do so.

See connection pooling for more information.

Issues Resolved

See the PyMongo 2.6 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.5.2 (2013/06/01)

Version 2.5.2 fixes a NULL pointer dereference issue when decoding an invalid DBRef.

Issues Resolved

See the PyMongo 2.5.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.5.1 (2013/05/13)

Version 2.5.1 is a minor release that fixes issues discovered after the release of 2.5. Most importantly, this release addresses some race conditions in replica set monitoring.

Issues Resolved

See the PyMongo 2.5.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.5 (2013/03/22)

Version 2.5 includes changes to support new features in MongoDB 2.4.

Important new features:

Note

authenticate() now raises a subclass of PyMongoError if authentication fails due to invalid credentials or configuration issues.

Issues Resolved

See the PyMongo 2.5 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.4.2 (2013/01/23)

Version 2.4.2 is a minor release that fixes issues discovered after the release of 2.4.1. Most importantly, PyMongo will no longer select a replica set member for read operations that is not in primary or secondary state.

Issues Resolved

See the PyMongo 2.4.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.4.1 (2012/12/06)

Version 2.4.1 is a minor release that fixes issues discovered after the release of 2.4. Most importantly, this release fixes a regression usingaggregate(), and possibly other commands, with mongos.

Issues Resolved

See the PyMongo 2.4.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.4 (2012/11/27)

Version 2.4 includes a few important new features and a large number of bug fixes.

Important new features:

Issues Resolved

See the PyMongo 2.4 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.3 (2012/08/29)

Version 2.3 adds support for new features and behavior changes in MongoDB 2.2.

Important New Features:

Warning

Starting with MongoDB 2.2 the getLastError command requires authentication when the server’s authentication features are enabled. Changes to PyMongo were required to support this behavior change. Users of authentication must upgrade to PyMongo 2.3 (or newer) for “safe” write operations to function correctly.

Issues Resolved

See the PyMongo 2.3 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.2.1 (2012/07/06)

Version 2.2.1 is a minor release that fixes issues discovered after the release of 2.2. Most importantly, this release fixes an incompatibility with mod_wsgi 2.x that could cause connections to leak. Users of mod_wsgi 2.x are strongly encouraged to upgrade from PyMongo 2.2.

Issues Resolved

See the PyMongo 2.2.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.2 (2012/04/30)

Version 2.2 adds a few more frequently requested features and fixes a number of bugs.

Special thanks go to Alex Grönholm for his contributions to Python 3 support and maintaining the original pymongo3 port. Christoph Simon, Wouter Bolsterlee, Mike O’Brien, and Chris Tompkinson also contributed to this release.

Important New Features:

Warning

A number of methods and method parameters that were deprecated in PyMongo 1.9 or older versions have been removed in this release. The full list of changes can be found in the following JIRA ticket:

https://jira.mongodb.org/browse/PYTHON-305

BSON module aliases from the pymongo package that were deprecated in PyMongo 1.9 have also been removed in this release. See the following JIRA ticket for details:

https://jira.mongodb.org/browse/PYTHON-304

As a result of this cleanup some minor code changes may be required to use this release.

Issues Resolved

See the PyMongo 2.2 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.1.1 (2012/01/04)

Version 2.1.1 is a minor release that fixes a few issues discovered after the release of 2.1. You can now useReplicaSetConnectionto run inline map reduce commands on secondaries. Seeinline_map_reduce() for details.

Special thanks go to Samuel Clay and Ross Lawley for their contributions to this release.

Issues Resolved

See the PyMongo 2.1.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.1 (2011/12/07)

Version 2.1 adds a few frequently requested features and includes the usual round of bug fixes and improvements.

Special thanks go to Alexey Borzenkov, Dan Crosta, Kostya Rybnikov, Flavio Percoco Premoli, Jonas Haag, and Jesse Davis for their contributions to this release.

Important New Features:

Issues Resolved

See the PyMongo 2.1 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 2.0.1 (2011/08/15)

Version 2.0.1 fixes a regression in GridIn when writing pre-chunked strings. Thanks go to Alexey Borzenkov for reporting the issue and submitting a patch.

Issues Resolved

Changes in Version 2.0 (2011/08/05)

Version 2.0 adds a large number of features and fixes a number of issues.

Special thanks go to James Murty, Abhay Vardhan, David Pisoni, Ryan Smith-Roberts, Andrew Pendleton, Mher Movsisyan, Reed O’Brien, Michael Schurter, Josip Delic and Jonas Haag for their contributions to this release.

Important New Features:

API changes:

Issues Resolved

See the PyMongo 2.0 release notes in JIRA for the list of resolved issues in this release.

Changes in Version 1.11 (2011/05/05)

Version 1.11 adds a few new features and fixes a few more bugs.

New Features:

API changes:

Warning

The pool_size, auto_start_request`, and timeout parameters for Connection have been completely removed in this release. They were deprecated in pymongo-1.4 and have had no effect since then. Please make sure that your code doesn’t currently pass these parameters when creating a Connection instance.

Issues resolved

Changes in Version 1.10.1 (2011/04/07)

Version 1.10.1 is primarily a bugfix release. It fixes a regression in version 1.10 that broke pickling of ObjectIds. A number of other bugs have been fixed as well.

There are two behavior changes to be aware of:

Issues resolved

Changes in Version 1.10 (2011/03/30)

Version 1.10 includes changes to support new features in MongoDB 1.8.x. Highlights include a modified map/reduce API including an inline map/reduce helper method, a new find_and_modify helper, and the ability to query the server for the maximum BSON document size it supports.

Warning

MongoDB versions greater than 1.7.4 no longer generate temporary collections for map/reduce results. An output collection name must be provided and the output will replace any existing output collection with the same name. map_reduce() now requires the out parameter.

Issues resolved

Changes in Version 1.9 (2010/09/28)

Version 1.9 adds a new package to the PyMongo distribution,bson. bson contains all of the BSON encoding and decoding logic, and the BSON types that were formerly in the pymongo package. The following modules have been renamed:

In addition, the following exception classes have been renamed:

The above exceptions now inherit from bson.errors.BSONErrorrather than pymongo.errors.PyMongoError.

Note

All of the renamed modules and exceptions above have aliases created with the old names, so these changes should not break existing code. The old names will eventually be deprecated and then removed, so users should begin migrating towards the new names now.

Warning

The change to the exception hierarchy mentioned above is possibly breaking. If your code is catchingPyMongoError, then the exceptions raised by bson will not be caught, even though they would have been caught previously. Before upgrading, it is recommended that users check for any cases like this.

Changes in Version 1.8.1 (2010/08/13)

Changes in Version 1.8 (2010/08/05)

Version 1.8 adds support for connecting to replica sets, specifying per-operation values for w and wtimeout, and decoding to timezone-aware datetimes.

Changes in Version 1.7 (2010/06/17)

Version 1.7 is a recommended upgrade for all PyMongo users. The full release notes are below, and some more in depth discussion of the highlights is here.

Changes in Version 1.6 (2010/04/14)

The biggest change in version 1.6 is a complete re-implementation ofgridfs with a lot of improvements over the old implementation. There are many details and examples of using the new API in this blog post. The old API has been removed in this version, so existing code will need to be modified before upgrading to 1.6.

Changes in Version 1.5.2 (2010/03/31)

Changes in Version 1.5.1 (2010/03/17)

Changes in Version 1.5 (2010/03/10)

Changes in Version 1.4 (2010/01/17)

Perhaps the most important change in version 1.4 is that we have decided to no longer support Python 2.3. The most immediate reason for this is to allow some improvements to connection pooling. This will also allow us to use some new (as in Python 2.4 ;) idioms and will help begin the path towards supporting Python 3.0. If you need to use Python 2.3 you should consider using version 1.3 of this driver, although that will no longer be actively supported.

Other changes:

Changes in Version 1.3 (2009/12/16)

Changes in Version 1.2.1 (2009/12/10)

Changes in Version 1.2 (2009/12/09)

Changes in Version 1.1.2 (2009/11/23)

Changes in Version 1.1.1 (2009/11/14)

Changes in Version 1.1 (2009/10/21)

Changes in Version 1.0 (2009/09/30)

Changes in Version 0.16 (2009/09/16)

Changes in Version 0.15.2 (2009/09/09)

Changes in Version 0.15.1 (2009/09/02)

Changes in Version 0.15 (2009/08/26)

Changes in Version 0.14.2 (2009/08/24)

Changes in Version 0.14.1 (2009/08/21)

Changes in Version 0.14 (2009/08/19)

Changes in Version 0.13 (2009/07/29)

Changes in Version 0.12 (2009/07/08)

Changes in Version 0.11.3 (2009/06/18)

Changes in Version 0.11.2 (2009/06/08)

Changes in Version 0.11.1 (2009/06/04)

Changes in Version 0.11 (2009/06/03)

Changes in Version 0.10.3 (2009/05/27)

Changes in Version 0.10.2 (2009/05/22)

Changes in Version 0.10.1 (2009/05/18)

Changes in Version 0.10 (2009/05/14)

Changes in Version 0.9.7 (2009/05/13)