Skip to content
Snippets Groups Projects
Commit b1eaf9c7 authored by Régis Behmo's avatar Régis Behmo Committed by Julia Eskew
Browse files

refactor: remove deprecated mongodb client class

As of pymongo 3.0, the MongoReplicaSetClient is deprecated in favour of
MongoClient. Thus, the creation of mongodb clients is simplified.

See: https://pymongo.readthedocs.io/en/stable/changelog.html#mongoclient-changes
parent 014a54c7
No related branches found
Tags release-2020-05-14-17.56
No related merge requests found
......@@ -30,19 +30,6 @@ def connect_to_mongodb(
handles AutoReconnect errors by retrying read operations, since these exceptions
typically indicate a temporary step-down condition for MongoDB.
"""
# The MongoReplicaSetClient class is deprecated in Mongo 3.x, in favor of using
# the MongoClient class for all connections. Update/simplify this code when using
# PyMongo 3.x.
if kwargs.get('replicaSet'):
# Enable reading from secondary nodes in the MongoDB replicaset by using the
# MongoReplicaSetClient class.
# The 'replicaSet' parameter in kwargs is required for secondary reads.
# The read_preference should be set to a proper value, like SECONDARY_PREFERRED.
mongo_client_class = pymongo.MongoReplicaSetClient
else:
# No 'replicaSet' in kwargs - so no secondary reads.
mongo_client_class = pymongo.MongoClient
# If the MongoDB server uses a separate authentication database that should be specified here
auth_source = kwargs.get('authsource', '') or None
......@@ -65,7 +52,7 @@ def connect_to_mongodb(
kwargs['read_preference'] = read_preference
mongo_conn = pymongo.database.Database(
mongo_client_class(
pymongo.MongoClient(
host=host,
port=port,
tz_aware=tz_aware,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment