Skip to content

Commit 7fb3f7a

Browse files
committed
1 parent 3d5bd91 commit 7fb3f7a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/clients.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from aiohttp import ClientResponseError, ClientResponse
1111
from motor.motor_asyncio import AsyncIOMotorClient
1212
from pymongo.errors import ConfigurationError
13+
from pymongo.uri_parser import parse_uri
1314

1415
from core.models import InvalidConfigError, getLogger
1516

@@ -445,7 +446,8 @@ def __init__(self, bot):
445446
raise RuntimeError
446447

447448
try:
448-
db = AsyncIOMotorClient(mongo_uri).modmail_bot
449+
database = parse_uri(mongo_uri).get('database') or 'modmail_bot'
450+
db = AsyncIOMotorClient(mongo_uri)[database]
449451
except ConfigurationError as e:
450452
logger.critical(
451453
"Your MongoDB CONNECTION_URI might be copied wrong, try re-copying from the source again. "
@@ -497,7 +499,8 @@ async def validate_database_connection(self, *, ssl_retry=True):
497499
'run "Certificate.command" on MacOS, '
498500
'and check certifi is up to date "pip3 install --upgrade certifi".'
499501
)
500-
self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True).modmail_bot
502+
database = parse_uri(mongo_uri).get('database') or 'modmail_bot'
503+
self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True)[database]
501504
return await self.validate_database_connection(ssl_retry=False)
502505
if "ServerSelectionTimeoutError" in message:
503506
logger.critical(

0 commit comments

Comments
 (0)