Skip to content

Database

Mr.Miss edited this page Feb 22, 2021 · 5 revisions

Database

Anjani uses MongoDB with Motor an asynchronous Python driver for MongoDB.


Fetching The Database

~Anjani.get_collection()

Get collection from the database.

Parameters:

  • name (str) - Collection name to fetch.

Example

from anjani_bot import listener, plugin

class TestDB(plugin.Plugin):
    name = "test-db"

    # It's recomended to load DataBase on __on_load__
    # this method executed when the plugin is loaded
    async def __on_load__(self):
        self.db_collection = self.bot.get_collection("<COLLECTION_NAME>")


   async def get_data(self, value) -> dict:
        data = await self.db_collection.find_one({'some_key': value})
        return data
Clone this wiki locally