Please see the below code with Python 3.12.2 and pymongo==4.6.3
:
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
uri = "mongodb+srv://cache-service:xxxx@serverlessinstance0.abc123.mongodb.net/?retryWrites=true&w=majority&appName=Foo"
client = MongoClient(uri, server_api=ServerApi("1"))
When the client
is instantiated, pymongo
resolves the URI, but it takes about 10 seconds on my Mac (macOS Sonoma version 14.3).
Tracing through the pymongo
source code, it seems pymongo.uri_parser.parse_uri
(passed the above URI and port 27017) is taking up all that time.
How can I work around having pymongo
parsing the mongodb+srv
internally and at runtime? I would like to avoid the URL resolution that is taking forever