Custom User Connection Strings for MongoDB Instances with Authentication

One of the many great things about ScaleGrid is that the platform allows you to provision MongoDB hosting deployments with authentication using a single click. MongoDB authentication is highly recommended for deployments exposed to the internet.

MongoDB has a concept of users per database. When you provision a deployment with authentication via ScaleGrid, we create a MongoDB admin user for the database admin. This user does have access to the new databases that are created, however, it can’t be accessed through the connection string. That is, you can connect to the admin database first, and then do a “use <DB>”.

We understand this is not the optimal experience for most users, so we recommend you can create a new user for each database you want to access via the connection string. Here are the steps to create a new user in <DB>:

  1. mongo <IP>:27017/admin -u “admin” -p “<password>”
  2. use <DB>;
  3. db.addUser(“<user>”, “<password>”);

You can check existing users in a database (if you imported a database in through MongoRestore) by typing the following command:

“use <DB>; db.system.users.find();”

You can now connect directly to <DB> using the newly created user via a connection string. A new connection string would look something like this:


Learn more about the advanced capabilities of our MongoDB hosting solutions through our DBaaS Help Docs.