16 lines
647 B
Python
16 lines
647 B
Python
import pymongo
|
|
from os import environ
|
|
|
|
MONGO_HOST = environ.get("MONGO_HOST")
|
|
MONGO_PORT = environ.get("MONGO_PORT")
|
|
MONGO_USERNAME = environ.get("MONGO_USERNAME")
|
|
MONGO_PASSWORD = environ.get("MONGO_PASSWORD")
|
|
MONGO_DATABASE = environ.get("MONGO_DATABASE")
|
|
|
|
if not MONGO_HOST or not MONGO_PORT or not MONGO_USERNAME or not MONGO_PASSWORD or not MONGO_DATABASE:
|
|
raise ValueError(
|
|
"MONGO_HOST, MONGO_PORT, MONGO_USERNAME, MONGO_PASSWORD and MONGO_DATABASE must be set")
|
|
|
|
database = pymongo.MongoClient(MONGO_HOST, int(
|
|
MONGO_PORT), username=MONGO_USERNAME, password=MONGO_PASSWORD, authSource=MONGO_DATABASE)[MONGO_DATABASE].client
|