Implementation
This handler is implemented usingpymongo, a Python library that contains tools for working with the MongoDB database.
The required arguments to establish a connection are as follows:
hostis the MongoDB connection string.
usernameis the username associated with the database.passwordis the password to authenticate your access.hostis the host name or IP address.portis the port through which TCP/IP connection is to be made.databaseis the database name to be connected.
If you installed MindsDB locally via pip, you need to install all handler dependencies manually. To do so, go to the handler’s folder (mindsdb/integrations/handlers/mongodb_handler) and run this command:
pip install -r requirements.txt.Usage
In order to make use of this handler and connect to the MongoDB database in MindsDB, the following syntax can be used:For this connection, we strongly suggest using the Mongo API instead of the SQL API.MindsDB has a dedicated Mongo API that allows you to use the full power of the MindsDB platform.
Using the Mongo API feels more natural for MongoDB users and allows you to use all the features of MindsDB.You can find the instructions on how to connect MindsDB to MongoDB Compass or MongoDB Shell and proceed with the Mongo API documentation for further details.
Once you connected MindsDB to MongoDB Compass or MongoDB Shell, you can run this command to connect your database to MindsDB:Then you can query your data, like this: