Connect Using Mongo Shell

Learn how to connect to MongoDB from the command line syntax and MongoDB web shell.

ScaleGrid MongoDB clusters are accessible via the command line interface (CLI). The mongo shell is the JS CLI to MongoDB.

📘

The ScaleGrid MongoDB Web Shell

We provide a web interface for the mongo shell via the Admin tab on the ScaleGrid console. The ScaleGrid MongoDB web shell is a limited version of the mongo console.

Get the Mongo Shell

📘

SSH Access

The mongo shell is also available on the instances that your database cluster is hosted on. If you have SSH access to the underlying instances, you can access the mongo shell available on them.

Download and install the mongo shell for the platform you want to connect to the MongoDB server from.

🚧

mongodump & mongorestore

mongodump, mongorestore and other binaries are important MongoDB utilities. They are accessed from the operation system CLI and need to be installed like the Mongo shell. These utilities are not available on the ScaleGrid MongoDB web shell.

Connect Using the Mongo Shell

You will need the following to be able to connect using the CLI:

  • User credentials. Follow the steps here in order to create a user if you haven't already created one.
  • For SSL enabled clusters, you will also need the SSL CA certificate file. It is available on the cluster details page, under the overview tab. Download and save the file.

The command line syntax for connecting to the admin database using the admin user credentials is provided on the ScaleGrid console under the Overview tab:

969

Here's where you find your command line syntax on the Cluster Details page

In general, the command line syntax is built in the following format:

mongo -u [username] -p [password] [host1:port]/[db]

Here's an example of a Connection String for a replica set without SSL enabled. In this example, we use the credentials of user 'testuser' to connect to the database 'test'.

mongo -u testuser -p <password> SG-Prod001-261.devservers.scalegrid.io:27017/test

Here's an example of a Connection String for the primary of a replica set with SSL:

mongo -u testuser -p <password> SG-Prod001-261.devservers.scalegrid.io:27017/test  --ssl --sslCAFile <path/to/file.crt>

The SSL CA certificate file pointed to in the sslCAFile argument above is the aforementioned SSL CA certificate file.