MongoDB
This is the implementation of the MongoDB data handler for MindsDB.
MongoDB is an open-source cross-platform document-oriented database program. It is classified as a NoSQL database.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- Install MindsDB locally via Docker or use MindsDB Cloud.
- To connect MongoDB to MindsDB, install the required dependencies following this instruction.
- Install or ensure access to MongoDB.
Implementation
This handler is implemented using pymongo
, a Python library that contains tools for working with the MongoDB database.
The required arguments to establish a connection are as follows:
host
is the MongoDB connection string.
Optionally, you can connect using these parameters:
username
is the username associated with the database.password
is the password to authenticate your access.host
is the host name or IP address.port
is the port through which TCP/IP connection is to be made.database
is the database name to be connected.
Usage
In order to make use of this handler and connect to the MongoDB database in MindsDB, the following syntax can be used:
You can use this established connection to query your table as follows:
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: