Spaces:
Sleeping
Sleeping
Commit
·
d1171e9
1
Parent(s):
e2eee76
Update requirements and enhance MongoDB connection: add certifi dependency for SSL configuration and modify connection settings for improved security and reliability.
Browse files- app/db.py +9 -1
- requirements.txt +2 -1
app/db.py
CHANGED
@@ -5,6 +5,7 @@ from typing import Optional
|
|
5 |
from motor.motor_asyncio import AsyncIOMotorClient
|
6 |
from pymongo.errors import ConnectionFailure
|
7 |
from dotenv import load_dotenv
|
|
|
8 |
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
@@ -23,7 +24,14 @@ async def connect_to_mongo():
|
|
23 |
"""Connect to MongoDB."""
|
24 |
global client
|
25 |
try:
|
26 |
-
client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Verify the connection
|
28 |
await client.admin.command('ping')
|
29 |
logger.info("Successfully connected to MongoDB")
|
|
|
5 |
from motor.motor_asyncio import AsyncIOMotorClient
|
6 |
from pymongo.errors import ConnectionFailure
|
7 |
from dotenv import load_dotenv
|
8 |
+
import certifi
|
9 |
|
10 |
# Load environment variables
|
11 |
load_dotenv()
|
|
|
24 |
"""Connect to MongoDB."""
|
25 |
global client
|
26 |
try:
|
27 |
+
# Configure client with proper SSL settings for Atlas
|
28 |
+
client = AsyncIOMotorClient(
|
29 |
+
MONGO_URI,
|
30 |
+
tls=True,
|
31 |
+
tlsCAFile=certifi.where(),
|
32 |
+
serverSelectionTimeoutMS=5000,
|
33 |
+
connectTimeoutMS=10000
|
34 |
+
)
|
35 |
# Verify the connection
|
36 |
await client.admin.command('ping')
|
37 |
logger.info("Successfully connected to MongoDB")
|
requirements.txt
CHANGED
@@ -27,4 +27,5 @@ motor>=3.3.2
|
|
27 |
python-dotenv>=1.0.1
|
28 |
sqlalchemy>=2.0.0
|
29 |
alembic>=1.13.0
|
30 |
-
psycopg2-binary>=2.9.9
|
|
|
|
27 |
python-dotenv>=1.0.1
|
28 |
sqlalchemy>=2.0.0
|
29 |
alembic>=1.13.0
|
30 |
+
psycopg2-binary>=2.9.9
|
31 |
+
certifi>=2024.2.2
|