23 lines
506 B
Python
23 lines
506 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("b-jokes")
|
|
|
|
def __getitem__(self, item):
|
|
return self.database.get_collection(item)
|
|
|
|
@cached_property
|
|
def jokes_collection(self):
|
|
return self["jokes"]
|
|
|
|
|
|
mongo = Mongo()
|