-
-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
from motor.motor_asyncio import AsyncIOMotorClient | ||
|
||
from config import MONGO_DB_URI | ||
|
||
from ..logging import LOGGER | ||
|
||
LOGGER(__name__).info("Connecting to your Mongo Database...") | ||
logger = LOGGER(__name__) | ||
|
||
logger.info("Connecting to your Mongo Database...") | ||
try: | ||
# Create the client instance | ||
_mongo_async_ = AsyncIOMotorClient(MONGO_DB_URI) | ||
mongodb = _mongo_async_.Anon | ||
LOGGER(__name__).info("Connected to your Mongo Database.") | ||
except: | ||
LOGGER(__name__).error("Failed to connect to your Mongo Database.") | ||
|
||
# Access the desired database | ||
mongodb = _mongo_async_.get_database() # Update this to your database name if needed | ||
|
||
# Test connection by executing a simple command | ||
asyncio.run(mongodb.command('m')) # Ensure MongoDB is reachable | ||
|
||
logger.info("Connected to your Mongo Database.") | ||
except Exception as e: | ||
logger.error(f"Failed to connect to your Mongo Database: {e}") | ||
exit() | ||
|