Navigation

Connect to a MongoDB Process

Overview

To connect to a MongoDB, retrieve the hostname and port information from Cloud Manager and then use a MongoDB client, such as the mongo shell or a MongoDB driver, to connect. To connect to a cluster, retrieve the hostname and port for the mongos process. To connect to a replica set or standalone process, retrieve the hostname and port for the mongod processes.

Firewall Rules

Firewall rules and user authentication affect your access to MongoDB. You must have access to the server and port of the MongoDB process. For information on firewalls on servers running MongoDB, see the firewall information in the Network Security document in the MongoDB manual.

If your MongoDB instance runs on Amazon Web Services (AWS), then the security group associated with the AWS servers also affects access. AWS security groups control inbound and outbound traffic to their associated servers.

Procedures

You can retrieve a shell command for connecting to your MongoDB instance, or you can retrieve the host and port number of a specific MongoDB process and create your own command for connecting using either shell or MongoDB driver.

Get a Shell Command to Connect to a MongoDB Instance

1

Click Deployment, then the Processes tab, then the Topology view.

2

On the line listing the cluster, replica set, or process, click the ellipsis icon and select Connect to this instance.

Cloud Manager provides a mongo shell command that you can use to connect to the MongoDB process.

Get the Host and Port for a MongoDB Process

1

Click Deployment, then the Processes tab, then the Topology view.

2

If the process is part of a sharded cluster, click the filter button for the type of process.

Click one of the following:

Shards Displays the mongod processes that host your data.
Configs Displays the mongod processes that run as config servers to store a sharded cluster’s metadata.
Mongos Displays the mongos processes that route data in a sharded cluster.
3

On the line listing the process, click Metrics.

Cloud Manager displays the hostname and port of the process at the top of the charts page.

Connect to a Deployment Using the Mongo Shell

Get the host and port using the above procedure. From a shell, run mongo and specify the host and port. For example:

mongo --username <user> --password <pass> --host <host> --port <port>

Connect to a Deployment Using a MongoDB Driver

Get the host and port using the above procedure. See your driver’s instructions for creating a connection string that specifies the hostname and port.

For sharded clusters, you specify the hostname and port of the mongos instance. For a replica set, you specify a seed list of all hosts in the replica set. Your driver will automatically connect to the primary. For example:

mongodb://[<username>:<password>@]hostname0<:port>[,hostname1:<port1>][,hostname2:<port2>][...][,hostnameN:<portN>]

See also

Data Explorer