-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmongodb.py
More file actions
32 lines (27 loc) · 1.04 KB
/
mongodb.py
File metadata and controls
32 lines (27 loc) · 1.04 KB
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
30
31
32
from pymongo import MongoClient
import asyncio
from logger import *
from config import host, port, db, collection
class MongoDB:
def __init__(self):
self.client = MongoClient(host, port)
self.db = self.client[db]
self.collections = self.db[collection]
async def func(self):
await asyncio.sleep(0.01)
return self.collections.find()
async def insert(self, data):
await asyncio.sleep(0.01)
try:
self.collections.insert_one(data)
except Exception as e:
logging.error(f'{e} {data}')
async def deleteData(self):
await asyncio.sleep(0.01)
response = self.collections.delete_many({})
if response.acknowledged:
logging.info('Данные успешно удалены!')
return 'Данные успешно удалены!'
else:
logging.error('Не удалось удалить данные.')
return 'Не удалось удалить данные.'