Mongo#

The Mongo module provides a MongoDB-based version of the DBContextStorage class. This class is used to store and retrieve context data in a MongoDB. It allows Chatsky to easily store and retrieve context data in a format that is highly scalable and easy to work with.

MongoDB is a widely-used, open-source NoSQL database that is known for its scalability and performance. It stores data in a format similar to JSON, making it easy to work with the data in a variety of programming languages and environments. Additionally, MongoDB is highly scalable and can handle large amounts of data and high levels of read and write traffic.

class MongoContextStorage(path, collection='context_collection')[source]#

Bases: DBContextStorage

Implements DBContextStorage with mongodb as the database backend.

Parameters:
  • path (str) – Database URI. Example: mongodb://user:password@host:port/dbname.

  • collection (str) – Name of the collection to store the data in.

static _adjust_key(key)[source]#

Convert a n-digit context id to a 24-digit mongo id

Return type:

Dict[str, ObjectId]

set_item_async(key, value)[source]#

Asynchronous method for storing Context.

Parameters:
  • key (Hashable) – Hashable key used to store Context instance.

  • value (Context) – Context to store.

get_item_async(key)[source]#

Asynchronous method for accessing stored Context.

Parameters:

key (Hashable) – Hashable key used to store Context instance.

Return type:

Context

Returns:

The stored context, associated with the given key.

del_item_async(key)[source]#

Asynchronous method for removing stored Context.

Parameters:

key (Hashable) – Hashable key used to identify Context instance for deletion.

contains_async(key)[source]#

Asynchronous method for finding whether any Context is stored with given key.

Parameters:

key (Hashable) – Hashable key used to check if Context instance is stored.

Return type:

bool

Returns:

True if there is Context accessible by given key, False otherwise.

len_async()[source]#

Asynchronous method for retrieving number of stored Contexts.

Return type:

int

Returns:

The number of stored Contexts.

clear_async()[source]#

Asynchronous method for clearing context storage, removing all the stored Contexts.