Spaces:
Runtime error
Runtime error
Fix MongoDB implementation
Browse files
src/ctp_slack_bot/db/mongo_db.py
CHANGED
@@ -51,24 +51,25 @@ class MongoDB(BaseModel):
|
|
51 |
logger.error("Failed to initialize MongoDB client: {}", e)
|
52 |
self._client = None
|
53 |
self._db = None
|
|
|
54 |
|
55 |
@property
|
56 |
def client(self: Self) -> AsyncIOMotorClient:
|
57 |
"""Get the MongoDB client instance."""
|
58 |
-
if
|
59 |
logger.warning("MongoDB client not initialized. Attempting to initialize.")
|
60 |
self._initialize_client()
|
61 |
-
if
|
62 |
raise ConnectionError("Failed to initialize MongoDB client")
|
63 |
return self._client
|
64 |
|
65 |
@property
|
66 |
def db(self: Self) -> Any:
|
67 |
"""Get the MongoDB database instance."""
|
68 |
-
if
|
69 |
logger.warning("MongoDB database not initialized. Attempting to initialize client.")
|
70 |
self._initialize_client()
|
71 |
-
if
|
72 |
raise ConnectionError("Failed to initialize MongoDB database")
|
73 |
return self._db
|
74 |
|
|
|
51 |
logger.error("Failed to initialize MongoDB client: {}", e)
|
52 |
self._client = None
|
53 |
self._db = None
|
54 |
+
raise
|
55 |
|
56 |
@property
|
57 |
def client(self: Self) -> AsyncIOMotorClient:
|
58 |
"""Get the MongoDB client instance."""
|
59 |
+
if self._client is None:
|
60 |
logger.warning("MongoDB client not initialized. Attempting to initialize.")
|
61 |
self._initialize_client()
|
62 |
+
if self._client is None:
|
63 |
raise ConnectionError("Failed to initialize MongoDB client")
|
64 |
return self._client
|
65 |
|
66 |
@property
|
67 |
def db(self: Self) -> Any:
|
68 |
"""Get the MongoDB database instance."""
|
69 |
+
if self._db is None:
|
70 |
logger.warning("MongoDB database not initialized. Attempting to initialize client.")
|
71 |
self._initialize_client()
|
72 |
+
if self._db is None:
|
73 |
raise ConnectionError("Failed to initialize MongoDB database")
|
74 |
return self._db
|
75 |
|
src/ctp_slack_bot/db/repositories/mongo_db_vectorized_chunk_repository.py
CHANGED
@@ -11,7 +11,7 @@ class MongoVectorizedChunkRepository(VectorizedChunkRepository):
|
|
11 |
|
12 |
def __init__(self, mongo_db: MongoDB):
|
13 |
self.mongo_db = mongo_db
|
14 |
-
self.collection = self.mongo_db.
|
15 |
|
16 |
# Create indexes for efficient queries
|
17 |
self.collection.create_index("chunk_id")
|
|
|
11 |
|
12 |
def __init__(self, mongo_db: MongoDB):
|
13 |
self.mongo_db = mongo_db
|
14 |
+
self.collection = self.mongo_db.db.get_collection("vectorized_chunks")
|
15 |
|
16 |
# Create indexes for efficient queries
|
17 |
self.collection.create_index("chunk_id")
|