MongoDB Storage Adapter¶
Before you can use this storage adapter you will need to install pymongo. An easy way to install it is to use the chatterbot[mongodb]
extra when installing ChatterBot. For example:
pip install chatterbot[mongodb]
You’ll also need to have a MongoDB server running. An easy way to run one locally is to use Docker:
version: "3.8"
services:
mongo:
# Use the latest stable version of the mongo image
image: mongo:8.0
# Expose the default MongoDB port
ports:
- "27017:27017"
# Persist the MongoDB data
volumes:
- ./.database/mongodb/db:/data/db
To start the MongoDB container, run:
docker compose up -d
Note
For more information on Docker and docker compose
, see the Docker Compose documentation.
MongoDB Adapter Class Attributes¶
- class chatterbot.storage.MongoDatabaseAdapter(**kwargs)[source]¶
The MongoDatabaseAdapter is an interface that allows ChatterBot to store statements in a MongoDB database.
- Parameters:
database_uri (str) – The URI of a remote instance of MongoDB. This can be any valid MongoDB connection string
database_uri='mongodb://example.com:8100/'
- create(**kwargs)[source]¶
Creates a new statement matching the keyword arguments specified. Returns the created statement.
- filter(**kwargs)[source]¶
Returns a list of statements in the database that match the parameters specified.