Spaces:
Runtime error
Runtime error
import os | |
from pymongo import MongoClient | |
from pymongo.database import Database | |
from pymongo.mongo_client import MongoClient | |
from pymongo.server_api import ServerApi | |
from dotenv import load_dotenv | |
load_dotenv(verbose=True) | |
USER_NAME = os.environ.get("DB_USERNAME") | |
PASSWORD = os.environ.get("DB_PASSWORD") | |
HOST = os.environ.get("DB_HOST") | |
MONGO_DATABASE_URL = f"mongodb+srv://{USER_NAME}:{PASSWORD}@{HOST}" | |
print(MONGO_DATABASE_URL) | |
client = MongoClient(MONGO_DATABASE_URL, server_api=ServerApi("1")) | |
def get_db() -> Database: | |
"""DB取得 | |
Returns: | |
Database: データべース | |
""" | |
db: Database = client.db | |
return db | |