pizda-bot/mongo.py
2022-12-17 16:53:03 +03:00

26 lines
591 B
Python

from functools import cached_property
import pymongo
import settings
class Mongo:
def __init__(self):
url = f"mongodb://{settings.MONGO_USER}:{settings.MONGO_PASSWORD}@{settings.MONGO_HOST}:27017/"
self.client = pymongo.MongoClient(url)
self.database = self.client.get_database("pizda-bot")
self.chats_collection.create_index([
("chat_id", 1)
])
def __getitem__(self, item):
return self.database.get_collection(item)
@cached_property
def chats_collection(self):
return self["chats"]
mongo = Mongo()