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:
CREATE DATABASE mongodb_datasource
WITH
ENGINE = 'mongodb',
PARAMETERS = {
"host": "mongodb+srv://admin:admin_pass@demo.mongodb.net/public"
};
Use the following parameters to establish the connection:
host: The connection string of the MongoDB server that includes user (admin), password (admin_pass), host and port (demo.mongodb.net), and database (public).
database: If the connection string does not include the /database path, provide it in this parameter.
Alternatively, the following set of connection parameters can be used:
username: The username associated with the database.
password: The password to authenticate your access.
host: The host of the MongoDB server.
port: The port through which TCP/IP connection is to be made.
database: The database name to be connected.
Usage
Retrieve data from a specified collection by providing the integration name and collection name:
SELECT *
FROM mongodb_datasource.my_collection
LIMIT 10;
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.
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 or UPDATE query.
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`