Description

MindsDB enables adding databases to your Mongo instance using the db.databases.insertOne() method.

Our MindsDB Mongo API supports creating a connection by passing the database credentials.

Syntax

Here is the syntax:

db.databases.insertOne({
    name: "mongo_int",
    engine: "mongodb",
    connection_args: {
            "port": 27017,
            "host": "mongodb+srv://admin:@localhost",
            "database": "test_data"
    }
});

Alternatively, you can use the host parameter alone, providing the connection string, as below:

db.databases.insertOne({
    name: "mongo_int",
    engine: "mongodb",
    connection_args: {
            "host": "mongodb+srv://user:pass@db.xxxyyy.mongodb.net/"
    }
});

On execution, we get:

{
	"acknowledged" : true,
	"insertedId" : ObjectId("62dff63c6cc2fa93e1d7f12c")
}

Where:

NameDescription
nameIdentifier for the data source to be created.
engineDatabase engine to be selected.
connection_args{"key":"value"} object storing the connection parameters such as port, host, database.

Example

Here is an example of how to connect to the local MongoDB.

db.databases.insertOne({
    name: "mongo_local",
    engine: "mongodb",
    connection_args: {
            "port": 27017,
            "host": "mongodb+srv://admin:@localhost",
            "database": "test_data"
  }
});

On execution, we get:

{
	"acknowledged" : true,
	"insertedId" : ObjectId("62dff63c6cc2fa93e1d7f12c")
}

You can list all the linked databases using the following command:

SHOW dbs;

On execution, we get:

+--------------------+
| Database           |
+--------------------+
| admin              |
| files              |
| information_schema |
| mindsdb            |
| mongo_int          |
| views              |
+--------------------+