mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-05 23:34:42 +00:00
migrated mongo storage from using deprecated motor to PyMongo
This commit is contained in:
parent
7a517f1eba
commit
1c0207e1d1
1 changed files with 6 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Any, Dict, Mapping, Optional, cast
|
||||
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from pymongo import AsyncMongoClient
|
||||
|
||||
from aiogram.exceptions import DataNotDictLikeError
|
||||
from aiogram.fsm.state import State
|
||||
|
|
@ -15,18 +15,18 @@ from aiogram.fsm.storage.base import (
|
|||
|
||||
class MongoStorage(BaseStorage):
|
||||
"""
|
||||
MongoDB storage required :code:`motor` package installed (:code:`pip install motor`)
|
||||
MongoDB storage required :code:`PyMongo` package installed (:code:`pip install PyMongo`).
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
client: AsyncIOMotorClient,
|
||||
client: AsyncMongoClient,
|
||||
key_builder: Optional[KeyBuilder] = None,
|
||||
db_name: str = "aiogram_fsm",
|
||||
collection_name: str = "states_and_data",
|
||||
) -> None:
|
||||
"""
|
||||
:param client: Instance of AsyncIOMotorClient
|
||||
:param client: Instance of AsyncMongoClient
|
||||
:param key_builder: builder that helps to convert contextual key to string
|
||||
:param db_name: name of the MongoDB database for FSM
|
||||
:param collection_name: name of the collection for storing FSM states and data
|
||||
|
|
@ -46,13 +46,13 @@ class MongoStorage(BaseStorage):
|
|||
Create an instance of :class:`MongoStorage` with specifying the connection string
|
||||
|
||||
:param url: for example :code:`mongodb://user:password@host:port`
|
||||
:param connection_kwargs: see :code:`motor` docs
|
||||
:param connection_kwargs: see :code:`PyMongo` docs
|
||||
:param kwargs: arguments to be passed to :class:`MongoStorage`
|
||||
:return: an instance of :class:`MongoStorage`
|
||||
"""
|
||||
if connection_kwargs is None:
|
||||
connection_kwargs = {}
|
||||
client = AsyncIOMotorClient(url, **connection_kwargs)
|
||||
client = AsyncMongoClient(url, **connection_kwargs)
|
||||
return cls(client=client, **kwargs)
|
||||
|
||||
async def close(self) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue