Skip to content

Commit

Permalink
Update mongo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DAXXTEAM authored Aug 15, 2024
1 parent 11c4f0f commit b9ebcd9
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions DAXXMUSIC/core/mongo.py
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()

0 comments on commit b9ebcd9

Please sign in to comment.