# MongoDB

* Type: Cache
* Description: Uses Mongo NoSQL DBs as Caches.

This store is best for production environment due to its high speed, TTL indexes and mainly disk based storage. Built on top of Python Async Driver of MongoDB [Motor](https://motor.readthedocs.io/en/stable/).

DB level sharding is possible by following the Mongo's docs for sharding and pass the necessary kwargs to the settings.

An extra installation is required: `pip install pyot[mongodb]`

## *class* `MongoDB`

Backend: `pyot.stores.mongodb.MongoDB`

Definitions:

* `__init__`
  * `db`: `str`

    > Name of the database to be used.
  * `host`: `str = '127.0.0.1'`

    > Host of the Mongo DB instance.
  * `port`: `int = 27017`

    > Port of the Mongo DB instance.
  * `expirations`: `Dict[str, int | float | timedelta] = None`
  * `log_level`: `int = 0`
  * `**kwargs`

    > Any extra kwargs provided will passed into `motor.motor_asyncio.AsyncIOMotorClient`. e.g. authentication params.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pyot.iann838.com/stores/mongodb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
