| 10 | # Ask Doubt on telegram @KingVJ01 |
| 11 | |
| 12 | class MongoDB: |
| 13 | def __init__(self, uri, db_name, collection): |
| 14 | self.uri = uri |
| 15 | self.db_name = db_name |
| 16 | self.collection = collection |
| 17 | self.client = None |
| 18 | self.db = None |
| 19 | self.files = None |
| 20 | |
| 21 | async def connect(self): |
| 22 | self.client = motor.motor_asyncio.AsyncIOMotorClient(self.uri) |
| 23 | self.db = self.client[self.db_name] |
| 24 | self.files = self.db[self.collection] |
| 25 | |
| 26 | async def close(self): |
| 27 | if self.client: |
| 28 | self.client.close() |
| 29 | |
| 30 | async def add_file(self, file_id): |
| 31 | file = {"file_id": file_id} |
| 32 | return await self.files.insert_one(file) |
| 33 | |
| 34 | async def is_file_exit(self, file_id): |
| 35 | f = await self.files.find_one({"file_id": file_id}) |
| 36 | return bool(f) |
| 37 | |
| 38 | async def get_all_files(self): |
| 39 | return self.files.find({}) |
| 40 | |
| 41 | async def drop_all(self): |
| 42 | return await self.files.drop() |
| 43 | |
| 44 | # Don't Remove Credit Tg - @VJ_Botz |
| 45 | # Subscribe YouTube Channel For Amazing Bot https://youtube.com/@Tech_VJ |