Skip to content

Connect a database from a self deployed MongoDB Community Edition

This guide will take you through all the neccessary steps needed to connect a database from a self deployed sharded cluster MongoDB Community Edition instance to Florentine.ai:

Create a readonly user

Start by connecting to your database via MongoDB shell. You might have to modify the command, i.e. add your own host and/or a different port, see Connect to a Deployment in the MongoDB docs in case you need help:

mongosh --host localhost --port 27017

Switch to the database you want to connect to Florentine.ai. Replace <db_name> with your actual database name:

use <db_name>

Run the following command to create a read-only user. Replace <db_name> with your actual database name, <db_username> with a username (i.e. florentine) and <db_password> with a strong password:

db.createUser({
  user: "<db_username>",
  pwd: "<db_password>",
  roles: [{ role: "read", db: "<db_name>" }]
})

If you have not yet configured your MongoDB instance to use authorization: enabled you must add it to ALL your mongod.conf and mongos.conf files on all cluster servers:

security:
  authorization: enabled

Then restart all mongos and mongod processes:

DANGER

Please note that all services connecting to the database without authentication will start failing. Make sure that you create an admin user before restarting and check that all other services use proper authentication before restarting.

Please see Use SCRAM to Authenticate Clients on Self-Managed Deployments in the MongoDB docs for more information.

sudo systemctl restart mongos
sudo systemctl restart mongod

Grant network access

Besides a user with database access Florentine.ai needs network access as well. You need to add the Florentine.ai IP 167.99.246.57 and 209.38.238.253 to bindIp inside your mongos.conf files on your mongos instances:

net:
  bindIp: 127.0.0.1,167.99.246.57,209.38.238.253

Restart your mongos process:

sudo systemctl restart mongos

Please note

Depending on your setup you might as well need to configure your firewall settings to allow the Florentine.ai IP 167.99.246.57 and 209.38.238.253.

Create the connection string

You should now be able to create the connection string you need to add in your Florentine.ai account. The structure of the connection string looks like this:

mongodb://<db_username>:<db_password>@<mongos1domain>:<port>,<mongos2domain>:<port>,<mongos3domain>:<port>/<db_name>

Now you need to replace <db_username>, <db_password> and <db_name> with your settings.

Also you need to replace the domain(s) and port(s) with your mongos instances (<mongos1domain>:<port>,<mongos2domain>:<port> and so on).

All mongos instances must be added and separated by a , so in case you have 3 mongos instances your final connection string should look comparable to this:

mongodb://florentine:[email protected]:27017,mongos2.florentine.ai:27017,mongos3.florentine.ai:27017/samples

Enter your final connection string on the connect page in your Florentine.ai account, click on Connect and if everything is configured correct you should see a list of the collections inside your database.