Skip to content

Commit a196315

Browse files
CHORE: migrate repositories to async pymongo client
1 parent 442983a commit a196315

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
motor
21
dill
32
python-dotenv
43
fastapi
54
uvloop
65
pydantic
76
numpy==1.26.4
8-
pymongo
7+
pymongo>=4.15
98
jsonpickle
109
gunicorn
1110
uvicorn

src/repositories/interface.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from pydantic import ValidationError
1313
from pymongo.errors import PyMongoError
1414
from pymongo.server_api import ServerApi
15-
from motor.motor_asyncio import AsyncIOMotorClient
15+
from pymongo import AsyncMongoClient
16+
1617
from fastapi import HTTPException, status
1718
from bson import ObjectId
1819

@@ -135,7 +136,7 @@ def _initialize_connection(self):
135136
self._connection_string = Secrets.get_secret(
136137
"MONGODB_CONNECTION_STRING"
137138
)
138-
self._client = AsyncIOMotorClient(
139+
self._client = AsyncMongoClient(
139140
self._connection_string,
140141
server_api=ServerApi("1"),
141142
maxIdleTimeMS=30000,
@@ -144,7 +145,10 @@ def _initialize_connection(self):
144145
serverSelectionTimeoutMS=60000,
145146
)
146147
self._collection = self._client.rocketpy[self.model.NAME]
147-
logger.info("MongoDB client initialized for %s", self.__class__)
148+
logger.info(
149+
"AsyncMongoClient initialized for %s",
150+
self.__class__,
151+
)
148152
except Exception as e:
149153
logger.error(
150154
f"Failed to initialize MongoDB client: {e}", exc_info=True

0 commit comments

Comments
 (0)