MongoDB

Guide to set up your MongoDB database with Velvet

In this guide, we outline the steps required to securely connect your MongoDB database to your Velvet workspace. You may be able to skip some of these steps if you've previously connected your database to other services.

Depending on whether you're starting a new project from scratch, or connecting a database that's already configured for a third-party tool - this will take between 10 minutes and 2 hours.

  1. Create a read-only user
  2. Set up a static IP address (guide here)
  3. Identify and copy your connection string
  4. Configure which database tables you want to connect with Velvet

1. Create a read-only user

It's best practice to create a user with read-only permissions for products like Velvet. Create a user with read-only permissions in MongoDB.

Connect to your MongoDB instance using the MongoDB shell or a MongoDB client. Switch to the admin database as you'll need administrative privileges to create roles.

Create the read only role velvet_read_all_data

db.createRole({
   role: "velvet_read_all_data",
   privileges: [
      {
         resource: { db: "", collection: "" },
         actions: ["find"]
      }
   ],
   roles: []
})

This example grants the find action on all collections in all databases, making it a read-only role. If you want to limit the read-only access to a specific database or collection, you can specify the database or collection in the resource field accordingly.

Assign the Role to a the velvet_readonly user with the password a very good password and assign them the velvet_read_all_data role.

db.createUser({
   user: "velvet_readonly",
   pwd: "mypassword",
   roles: ["velvet_read_all_data"]
})

Once you've created a read-only user, move on to the next step.

2. Set up a static IP address

Set up a static IP using our static IP configuration guide.

3. Identify and copy your connection string

Find your database connection string to paste it into your Velvet workspace config. If you already have a connection string, jump ahead to section #4.

Or, follow the guide below for building your connection string for the first time.

Read our general guide on URI construction here.

For a self-hosted MongoDB cluster

  1. Find the hostnames or IP addresses of the servers and the name of the replica set.
  2. Specify the individual servers in the replica set in the connection string, and the replica set name.
mongodb://<host1>:<port1>,<host2>:<port2>,<host3>:<port3>/<database>?replicaSet=<replicaSetName>`
  1. Copy the connection string.
  2. Paste your URI into Velvet database config, and select the tables you want included. See a guide here.

For AtlasUI

  1. Navigate to App services and navigate to your application.
  1. Navigate to “Linked Data Sources” in the left side bar.
  2. Click on the Data Source you're connecting to.
  3. Choose the Authentication Method using a read-only user and copy the connection string.

4. Configure your database and tables on Velvet

Configure MongoDB as a remote database connection and select which tables you want connected.

  1. Tap into a workspace in your Velvet dashboard
  2. Tap "Add a data source"
  3. Select type "Remote database"
  4. Name your database
  5. Paste in your database URI. Note: After providing your database credentials for the first time, we manage the connection using ClickHouse. If required, you can add ClickHouse's Static IPs to an allowlist - Read their API documentation here.
  1. Select and configure the table you want to connect as a source.
  1. Name your table and create the source.
  1. Repeat steps 6 and 7 to add each table you want included as a data source.
  2. You can now view, search, and filter data inside your database source.

Great job, you’ve connected your internal database as a data source. We’ll capture data from your connected tables so you can query them in your Velvet workspace.

Email [email protected] for support or feedback.