add mongoDb support

This commit is contained in:
Lei PAN
2022-06-16 09:26:49 +02:00
parent 8c536624b1
commit 636ef124d5
4 changed files with 35 additions and 9 deletions
+29
View File
@@ -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()