File size: 653 Bytes
30099ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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