-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
38 lines (31 loc) · 1.21 KB
/
db.py
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
31
32
33
34
35
36
37
38
"""R
MongoDB Initialization Module.
This module sets up the connection to the MongoDB database.
Attributes:
MONGO_USERNAME (str): An environment variable having MongoDB username.
Defaults to "username".
MONGO_PASSWORD (str): An environment variable having MongoDB password.
Defaults to "password".
MONGO_PORT (str): MongoDB port. Defaults to "27017".
MONGO_URI (str): MongoDB URI.
MONGO_DATABASE (str): MongoDB database name.
client (MongoClient): MongoDB client.
db (Database): MongoDB database.
ccdb (Collection): MongoDB collection for Clubs Council.
docsstoragedb (Collection): MongoDB collection for storing documents.
"""
from os import getenv
from pymongo import MongoClient
# get mongodb URI and database name from environment variale
MONGO_URI = "mongodb://{}:{}@mongo:{}/".format(
getenv("MONGO_USERNAME", default="username"),
getenv("MONGO_PASSWORD", default="password"),
getenv("MONGO_PORT", default="27107"),
)
MONGO_DATABASE = getenv("MONGO_DATABASE", default="default")
# instantiate mongo client
client = MongoClient(MONGO_URI)
# get database
db = client[MONGO_DATABASE]
ccdb = db.cc
docsstoragedb = db.docsstorage