From 44454a2a1fcf364ddff327a8da2fdd899bf041af Mon Sep 17 00:00:00 2001 From: julius Date: Mon, 2 May 2022 16:58:52 -0700 Subject: [PATCH 1/4] initial commit --- doc/changelog.rst | 13 ++++++++----- doc/migrate-to-pymongo4.rst | 24 ++++++++++++++++++++++++ pymongo/mongo_client.py | 4 ++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index 0fe2300120..abe2640989 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -89,6 +89,14 @@ Changes in Version 4.0 .. 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 :class:`~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. + See the :doc:`migrate-to-pymongo4` for more details. + 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 :doc:`migrate-to-pymongo4` @@ -217,11 +225,6 @@ Breaking Changes in 4.0 - ``tz_aware``, an argument for :class:`~bson.json_util.JSONOptions`, now defaults to ``False`` instead of ``True``. ``json_util.loads`` now decodes datetime as naive by default. -- ``directConnection`` URI option and keyword argument to :class:`~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 :meth:`~pymongo.collection.Collection.find`. - ``name`` is now a required argument for the :class:`pymongo.driver_info.DriverInfo` class. diff --git a/doc/migrate-to-pymongo4.rst b/doc/migrate-to-pymongo4.rst index 5f75ed1760..7ee844ed88 100644 --- a/doc/migrate-to-pymongo4.rst +++ b/doc/migrate-to-pymongo4.rst @@ -74,6 +74,30 @@ 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. +Here are some example errors that you might see + +.. code-block:: + + _select_servers_loop + raise ServerSelectionTimeoutError( + pymongo.errors.ServerSelectionTimeoutError: mongo_node2: [Errno 8] nodename nor servname + provided, or not known,mongo_node1:27017 + +.. code-block:: + + ServerSelectionTimeoutError: No servers match selector "Primary()", Timeout: 30s, + Topology Description: ... + + +Additionally, the "isWritablePrimary" attribute of a hello command sent back by the server will +always be True if ``directConnection=False``:: + + doc = client.admin.command('hello') + result = doc['isWritablePrimary'] + print(result) + >> True + + The waitQueueMultiple parameter is removed .......................................... diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index 5c7e7cb176..b8d780b48a 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -137,6 +137,10 @@ def __init__( ) -> None: """Client for a MongoDB instance, a replica set, or a set of mongoses. + .. warning:: Starting in PyMongo 4.0, ``directConnection`` now has a default value of + False instead of None (which is the same as specifying ``directionConnection=True``). + Please see the :ref:`pymongo4-migration-guide` for more details. + The client object is thread-safe and has connection-pooling built in. If an operation fails because of a network error, :class:`~pymongo.errors.ConnectionFailure` is raised and the client From 55e4a7dcc4cd1013d6cd0b55598c29d026ed96c1 Mon Sep 17 00:00:00 2001 From: julius Date: Mon, 2 May 2022 17:42:26 -0700 Subject: [PATCH 2/4] link to direct connection subsection, fix wording, fix error examples --- doc/changelog.rst | 8 +++++++- doc/migrate-to-pymongo4.rst | 12 +++++++----- pymongo/mongo_client.py | 5 +++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index abe2640989..1fd5ea8dd3 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -95,7 +95,8 @@ Changes in Version 4.0 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. - See the :doc:`migrate-to-pymongo4` for more details. + For more details, see the relevant section of the PyMongo 4.x migration + guide: :ref:`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. @@ -225,6 +226,11 @@ Breaking Changes in 4.0 - ``tz_aware``, an argument for :class:`~bson.json_util.JSONOptions`, now defaults to ``False`` instead of ``True``. ``json_util.loads`` now decodes datetime as naive by default. +- ``directConnection`` URI option and keyword argument to :class:`~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 :meth:`~pymongo.collection.Collection.find`. - ``name`` is now a required argument for the :class:`pymongo.driver_info.DriverInfo` class. diff --git a/doc/migrate-to-pymongo4.rst b/doc/migrate-to-pymongo4.rst index 7ee844ed88..60d633e6c5 100644 --- a/doc/migrate-to-pymongo4.rst +++ b/doc/migrate-to-pymongo4.rst @@ -65,6 +65,8 @@ get the same behavior. MongoClient ----------- +.. _pymongo4-migration-direct-connection: + ``directConnection`` defaults to False ...................................... @@ -74,7 +76,9 @@ 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. -Here are some example errors that you might see +If you see any :exc:`~pymongo.errors.ServerSelectionTimeoutError`'s after upgrading from PyMongo 3 to 4.x, you likely +need to add ``directConnection=True`` when creating the client. +Here are some example errors: .. code-block:: @@ -92,10 +96,8 @@ Here are some example errors that you might see Additionally, the "isWritablePrimary" attribute of a hello command sent back by the server will always be True if ``directConnection=False``:: - doc = client.admin.command('hello') - result = doc['isWritablePrimary'] - print(result) - >> True + >>> client.admin.command('hello')['isWritablePrimary'] + True The waitQueueMultiple parameter is removed diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index b8d780b48a..e4d457b864 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -138,8 +138,9 @@ def __init__( """Client for a MongoDB instance, a replica set, or a set of mongoses. .. warning:: Starting in PyMongo 4.0, ``directConnection`` now has a default value of - False instead of None (which is the same as specifying ``directionConnection=True``). - Please see the :ref:`pymongo4-migration-guide` for more details. + False instead of None. + For more details, see the relevant section of the PyMongo 4.x migration guide: + :ref:`pymongo4-migration-direct-connection`. The client object is thread-safe and has connection-pooling built in. If an operation fails because of a network error, From 3e15310438b833c6cf771d82574cf2b5e2be120d Mon Sep 17 00:00:00 2001 From: julius Date: Mon, 2 May 2022 18:05:48 -0700 Subject: [PATCH 3/4] fixed indentation --- pymongo/mongo_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index e4d457b864..6601c18aca 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -139,8 +139,8 @@ def __init__( .. warning:: Starting in PyMongo 4.0, ``directConnection`` now has a default value of False instead of None. - For more details, see the relevant section of the PyMongo 4.x migration guide: - :ref:`pymongo4-migration-direct-connection`. + For more details, see the relevant section of the PyMongo 4.x migration guide: + :ref:`pymongo4-migration-direct-connection`. The client object is thread-safe and has connection-pooling built in. If an operation fails because of a network error, From 0f41812a81e38a2006d1804c40514070830176de Mon Sep 17 00:00:00 2001 From: julius Date: Mon, 2 May 2022 19:01:13 -0700 Subject: [PATCH 4/4] remove two lines --- doc/migrate-to-pymongo4.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/migrate-to-pymongo4.rst b/doc/migrate-to-pymongo4.rst index 60d633e6c5..d70d7b8a2c 100644 --- a/doc/migrate-to-pymongo4.rst +++ b/doc/migrate-to-pymongo4.rst @@ -82,8 +82,6 @@ Here are some example errors: .. code-block:: - _select_servers_loop - raise ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError: mongo_node2: [Errno 8] nodename nor servname provided, or not known,mongo_node1:27017