~Anjani uses our own implementation of MongoDB to fit our need of asynchronous methods and annotation.
It's almost the same like Motor but some methods were built different and removed (deprecated).

Fetching The Database


Get collection from the database.


  • name (str) - Collection name to fetch.


from typing import Any, Optional, MutableMapping

from anjani import command, plugin

class ExampleDB(plugin.Plugin):
    name = "Example DB"

    # recommended to initialized database inside on_load listener
    async def on_load(self) -> None:
        self.db ="<COLLECTION_NAME>")

    async def get_data(self, key: str, value: Any) -> Optional[MutableMapping[str, Any]]:
        return await self.db.find_one({key: value})

    async def cmd_fetchdb(self, ctx: command.Context) -> str:
        data = await self.get_data("chat_id",
        if not data:
            return "No data found"
        return "Fetched database complete"