-
Notifications
You must be signed in to change notification settings - Fork 1
/
db.py
24 lines (19 loc) · 854 Bytes
/
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
"""
This file initializes a Python MongoDB client that can be shared across files.
Since the only other code file is `app.py`, the code below could be moved to
`app.py`, but with larger codebases where multiple files interact with the
MongoDB client, this file will come in handy.
"""
import os
from dotenv import load_dotenv
from pymongo import MongoClient
# This is only a sample, so the `.env.sample` is used. For your project, you should
# use `.env`. BE SURE TO INCLUDE THIS FILE IN YOUR `.gitignore` FILE OR ELSE YOUR
# MONGODB CREDENTIALS WILL BE PUBLISHED TO GITHUB!
#
# Disclaimer: The URIs in this file are only meant to be used for this sample.
# Please create your own collection to store your data.
#
# https://www.mongodb.com/docs/atlas/getting-started/
load_dotenv('.env.sample')
client = MongoClient(os.getenv("MONGO_URI_MASTER"))