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.


Before proceeding, ensure the following prerequisites are met:

  1. Install MindsDB locally via Docker or Docker Desktop.
  2. To connect MongoDB to MindsDB, install the required dependencies following this instruction.
  3. Install or ensure access to MongoDB.


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.


In order to make use of this handler and connect to the MongoDB database in MindsDB, the following syntax can be used:

CREATE DATABASE mongo_datasource
  ENGINE = 'mongodb',
    "host": "",
    "port": 27017,
    "username": "mongo",
    "password": "password",
    "database": "database"

You can use this established connection to query your table as follows:

FROM mongo_datasource.demo;

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:

test> use mindsdb
mindsdb> db.databases.insertOne({
              name: "mongo_datasource",
              engine: "mongodb",
              connection_args: {
                      "host": "mongodb+srv://"

Then you can query your data, like this:

mindsdb> use mongo_datasource
mongo_datasource> db.demo.find({}).limit(3)