MongoDB

Guide to connect MongoDB to Velvet

Connect your MongoDB database to your Velvet workspace. You can skip some steps if you've previously connected to other services.

1. Create a read-only user

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"]
})

2. Set static IPs

Configure network restrictions to allow Velvet's static IP addresses. Follow our static IP configuration guide.

3. Build your connection string

Read our general guide on URI construction here. The Mongo-specific overview is below.

If you already have a connection string - copy it and skip to step #4.

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. Connect your database

Connect your database to Velvet using your connection string.

  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
  6. Press create

If you run into any errors, schedule a call or email [email protected].

Once your database is connected, you're ready to use the AI SQL editor. Close out of the modal to start using the editor on top of your database.

Schema mapping is optional, and only required if you want to query multiple sources at the same time.

5. [optional] Schema mapping for unified sources

This configuration is only required to query multiple data sources at the same time. For example - two databases at the same time, or stripe webhooks alongside your database tables.

You can set up this unified mapping any time.

Add schema mapping context

After you connect your database, you'll be prompted to configure the schema for each table you set up.

Name your table to create this source.

Repeat these schema mapping steps for each table you want included as a unified data source.

Get help

Email [email protected] if you need additional support.