From ff32f65971bf573898cf4211132414865d2eaa27 Mon Sep 17 00:00:00 2001 From: Martin Uhrin Date: Sun, 25 Aug 2024 19:51:47 +0200 Subject: [PATCH] Updated to pymongo 4 --- mincepy/mongo/mongo_archive.py | 8 ++++++-- pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mincepy/mongo/mongo_archive.py b/mincepy/mongo/mongo_archive.py index cd61672..c27c00e 100644 --- a/mincepy/mongo/mongo_archive.py +++ b/mincepy/mongo/mongo_archive.py @@ -633,15 +633,19 @@ def pymongo_connect(uri, database: str = None, timeout=30000): # URI Format is: # mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[database][?options]] try: - parsed = pymongo.uri_parser.parse_uri(uri) + parsed: dict = pymongo.uri_parser.parse_uri(uri) except pymongo.errors.InvalidURI as exc: raise ValueError(str(exc)) from exc if not parsed.get("database", None): raise ValueError(f"Failed to supply database on MongoDB uri: {uri}") + kwargs = {} + if "uuidRepresentation" not in parsed["options"]: + kwargs["uuidRepresentation"] = "standard" + try: - client = pymongo.MongoClient(uri, connect=True, serverSelectionTimeoutMS=timeout) + client = pymongo.MongoClient(uri, connect=True, serverSelectionTimeoutMS=timeout, **kwargs) database = client.get_default_database() return MongoArchive(database) except pymongo.errors.ServerSelectionTimeoutError as exc: diff --git a/pyproject.toml b/pyproject.toml index 2e0c078..f99e560 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ requires-python = '>=3.8' dependencies = [ "deprecation", "dnspython", # Needed to be able to connect using domain name rather than IP - "pymongo<4.0", + "pymongo<5.0", "litemongo", "importlib-metadata<5.0", # see: https://stackoverflow.com/questions/73929564/entrypoints-object-has-no-attribute-get-digital-ocean "mongomock",