I told you to fuck off
This commit is contained in:
@@ -3,6 +3,8 @@ import json
|
||||
from pymongo import MongoClient
|
||||
from pymongo.synchronous.database import Database
|
||||
|
||||
from src.models import logger
|
||||
|
||||
|
||||
class MongoService:
|
||||
|
||||
@@ -16,19 +18,21 @@ class MongoService:
|
||||
|
||||
def insert(self, collection : str, data : object):
|
||||
try :
|
||||
logger.log_info(f"Mongo data : {data}")
|
||||
collection = self._db[collection]
|
||||
payload = self._to_document(data)
|
||||
logger.log_info(f"Formatted data : {payload}")
|
||||
result = collection.insert_one(payload)
|
||||
return result.inserted_id
|
||||
except Exception as e:
|
||||
print(e)
|
||||
logger.log_info(e)
|
||||
|
||||
def find(self, collection: str, field: str, value):
|
||||
try :
|
||||
collection = self._db[collection]
|
||||
return list(collection.find({field: value}))
|
||||
except Exception as e:
|
||||
print(e)
|
||||
logger.log_info(e)
|
||||
|
||||
def _to_document(self, obj):
|
||||
if obj is None or isinstance(obj, (str, int, float, bool)):
|
||||
|
||||
Reference in New Issue
Block a user