-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ru Chern Chong
committed
May 23, 2024
1 parent
a83027f
commit 27d961e
Showing
4 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from pymongo import MongoClient | ||
|
||
load_dotenv() | ||
|
||
|
||
class MongoDBConnection: | ||
def __init__(self, connection_string=os.environ.get("MONGODB_URI")): | ||
self.client = MongoClient(connection_string) | ||
self.db = self.client[os.environ.get("MONGODB_DB_NAME")] | ||
|
||
@property | ||
def database(self): | ||
return self.db | ||
|
||
def close_connection(self): | ||
self.client.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters