forked from CUBigDataClass/newsbuff-datafetch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongodb.py
More file actions
29 lines (22 loc) · 749 Bytes
/
Copy pathmongodb.py
File metadata and controls
29 lines (22 loc) · 749 Bytes
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
import os
from os.path import dirname, join
import pymongo
from dotenv import load_dotenv
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
DB_URL = os.environ.get('DB_URL', None)
def dbConnection():
try:
#DB entry
# Replace the uri string with your MongoDB deployment's connection string.
# set a 5-second connection timeout
client = pymongo.MongoClient(DB_URL, serverSelectionTimeoutMS=5000)
print("Connected to the DB server.")
# print(client.server_info())
return client
except Exception as error:
print("Unable to connect to the DB server.")
raise error
def createdb(client):
mydb = client["testdbnewsbuff"]
return mydb