MongoDB
This documentation describes the integration of MindsDB with MongoDB, a document database with the scalability and flexibility that you want with the querying and indexing that you need.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- Install MindsDB locally via Docker or Docker Desktop.
Connection
Establish a connection to MongoDB from MindsDB by executing the following SQL command:
Required connection parameters include the following:
host
: The host name, IP address or connection string of the MongoDB server.
Optional connection parameters include the following:
username
: The username associated with the database.password
: The password to authenticate your access.port
: The port through which TCP/IP connection is to be made.database
: The database name to be connected. This will be required if the connection string is missing the/database
path.
Usage
Retrieve data from a specified collection by providing the integration name and collection name:
The above examples utilize mongodb_datasource
as the datasource name, which is defined in the CREATE DATABASE
command.
At the moment, this integration only supports SELECT
and UPDATE
queries.
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:
Troubleshooting Guide
Database Connection Error
- Symptoms: Failure to connect MindsDB with the MongoDB server.
- Checklist:
- Make sure the MongoDB server is active.
- Confirm that host and credentials provided are correct. Try a direct MongoDB connection using a client like MongoDB Compass.
- Ensure a stable network between MindsDB and MongoDB. For example, if you are using MongoDB Atlas, ensure that the IP address of the machine running MindsDB is whitelisted.
Unknown statement
- Symptoms: Errors related to the issuing of unsupported queries to MongoDB via the integration.
- Checklist:
- Ensure the query is a
SELECT
orUPDATE
query.
- Ensure the query is a
SQL statement cannot be parsed by mindsdb_sql
- Symptoms: SQL queries failing or not recognizing collection names containing special characters.
- Checklist:
- Ensure table names with special characters are enclosed in backticks.
- Examples:
- Incorrect: SELECT * FROM integration.travel-data
- Incorrect: SELECT * FROM integration.‘travel-data’
- Correct: SELECT * FROM integration.`travel-data`