add mongoDb support
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import logging
|
||||
|
||||
from pymongo import MongoClient
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
|
||||
MONGO_DB_URL = "91.121.210.60"
|
||||
|
||||
|
||||
class MongoDbManager:
|
||||
def __init__(self):
|
||||
client = MongoClient(MONGO_DB_URL, username='appointment', password='Rdv@2022', authSource='appointment')
|
||||
self.db = client.appointment
|
||||
self.logger = logging.getLogger("mongoDb")
|
||||
|
||||
def insert_one(self, collection_name: str, dict: dict):
|
||||
collection_to_use = self.db[collection_name]
|
||||
collection_to_use.insert_one(dict)
|
||||
|
||||
def insert_reserve_result(self, collection_name, reserve: ReserveResultPojo):
|
||||
try:
|
||||
collection_to_use = self.db[collection_name]
|
||||
collection_to_use.replace_one(filter={'_id': reserve.id, }, replacement=reserve.to_firestore_dict(),
|
||||
upsert=True)
|
||||
except Exception as Error:
|
||||
print(Error)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
db_manager = MongoDbManager()
|
||||
Reference in New Issue
Block a user