Connect to a MongoDB Process
On this page
- OAuth 2.0 authentication for programmatic access to Cloud Manager is available as a Preview feature.
- The feature and the corresponding documentation might change at any time during the Preview period. To use OAuth 2.0 authentication, create a service account to use in your requests to the Cloud Manager Public API.
Overview
To connect to a MongoDB, retrieve the hostname and port information
from Cloud Manager and then use a MongoDB client, such as mongosh
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
In MongoDB Cloud Manager, go to the Deployment page for your project.
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it's not already displayed, select your desired project from the Projects menu in the navigation bar.
If the Deployment page is not already displayed, click Deployment in the sidebar.
The Deployment page displays.
Go to the Processes page.
Click the Processes tab for your deployment.
The Processes page displays.
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
command that you can use
to connect to the MongoDB process.
Get the Host and Port for a MongoDB Process
In MongoDB Cloud Manager, go to the Deployment page for your project.
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it's not already displayed, select your desired project from the Projects menu in the navigation bar.
If the Deployment page is not already displayed, click Deployment in the sidebar.
The Deployment page displays.
Go to the Processes page.
Click the Processes tab for your deployment.
The Processes page displays.
(Optional) For sharded clusters, filter which process type is listed.
The four buttons are listed in the following order, left to right: Shards, Configs, Mongos, and BIs.
Process | Displays |
---|---|
Shards | mongod processes that host your data. |
Configs | mongod processes that run as config
servers to store a sharded cluster's metadata. |
Mongos | mongos processes that route data in a sharded
cluster. |
BIs | BI processes that access data
in a sharded cluster. |
Connect to a Deployment Using mongosh
Get the host and port using the previous procedure. From a shell, run mongosh
and specify the
host and port. For example:
mongosh --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>]