diff --git a/core/clients.py b/core/clients.py index 61c39fdd4b..9e3954dfbc 100644 --- a/core/clients.py +++ b/core/clients.py @@ -10,6 +10,7 @@ from aiohttp import ClientResponseError, ClientResponse from motor.motor_asyncio import AsyncIOMotorClient from pymongo.errors import ConfigurationError +from pymongo.uri_parser import parse_uri from core.models import InvalidConfigError, getLogger @@ -448,7 +449,8 @@ def __init__(self, bot): raise RuntimeError try: - db = AsyncIOMotorClient(mongo_uri).modmail_bot + database = parse_uri(mongo_uri).get('database') or 'modmail_bot' + db = AsyncIOMotorClient(mongo_uri)[database] except ConfigurationError as e: logger.critical( "Your MongoDB CONNECTION_URI might be copied wrong, try re-copying from the source again. " @@ -500,7 +502,8 @@ async def validate_database_connection(self, *, ssl_retry=True): 'run "Certificate.command" on MacOS, ' 'and check certifi is up to date "pip3 install --upgrade certifi".' ) - self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True).modmail_bot + database = parse_uri(mongo_uri).get('database') or 'modmail_bot' + self.db = AsyncIOMotorClient(mongo_uri, tlsAllowInvalidCertificates=True)[database] return await self.validate_database_connection(ssl_retry=False) if "ServerSelectionTimeoutError" in message: logger.critical(