Skip to content

Commit

Permalink
Updated to pymongo 4
Browse files Browse the repository at this point in the history
  • Loading branch information
muhrin committed Aug 25, 2024
1 parent f74bf8c commit ff32f65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions mincepy/mongo/mongo_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ff32f65

Please sign in to comment.