mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
26 lines
603 B
Python
26 lines
603 B
Python
from application.core import settings
|
|
from pymongo import MongoClient
|
|
from flask import current_app, g
|
|
|
|
|
|
class MongoDB:
|
|
_client = None
|
|
|
|
@classmethod
|
|
def get_client(cls):
|
|
"""
|
|
Get the MongoDB client instance, creating it if necessary.
|
|
"""
|
|
if cls._client is None:
|
|
cls._client = MongoClient(settings.MONGO_URI)
|
|
return cls._client
|
|
|
|
@classmethod
|
|
def close_client(cls):
|
|
"""
|
|
Close the MongoDB client connection.
|
|
"""
|
|
if cls._client is not None:
|
|
cls._client.close()
|
|
cls._client = None
|