Connecting to a Single Node Instance Using Mongo Shell (Private Network)
Mongo shell is the default client for the MongoDB database server. You can use Mongo Shell to connect to DB instances, and query, update, and manage data in databases. DDS is compatible with MongoDB. Mongo Shell is a part of the MongoDB client. To use Mongo Shell, download and install the MongoDB client first, and then use the Mongo shell to connect to the DB instance.
By default, a DDS instance provides a private IP address. If your applications are deployed on an ECS and are in the same region and VPC as DDS instances, you can connect to DDS instances using a private IP address to achieve a fast transmission rate and high security.
This section describes how to use Mongo Shell installed on a Linux ECS to connect to a single node instance over a private network.
You can connect to an instance using an SSL connection or an unencrypted connection. The SSL connection is encrypted and more secure. To improve data transmission security, connect to instances using SSL.
Prerequisites
- For details about how to create and log in to an ECS, see Purchasing an ECS and Logging In to an ECS.
- Install the MongoDB client on the ECS.
For details about how to install a MongoDB client, see How Can I Install a MongoDB Client?
- The ECS can communicate with the DDS instance. For details, see ECS.
SSL
If you connect to an instance over the SSL connection, enable SSL first. Otherwise, an error is reported. For details about how to enable SSL, see Enabling and Disabling SSL.
- Log in to the management console.
- Click in the upper left corner and select a region and a project.
- Click in the upper left corner of the page and choose Databases > Document Database Service.
- On the Instances page, click the instance name.
- In the navigation pane on the left, choose Connections.
- In the Basic Information area, click next to the SSL field.
- Import the root certificate to the Linux or Windows ECS. For details, see How Can I Import the Root Certificate to a Windows or Linux OS?
- Connect to a DDS instance.
Using a private IP address
Example command:
./mongo --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p --authenticationDatabase admin --ssl --sslCAFile<FILE_PATH> --sslAllowInvalidHostnames
Parameter description:
- DB_HOST is the private IP address of the instance to be connected.
On the Instances page, click the instance name. The Basic Information page is displayed. Choose Connections. On the Private Connection tab, obtain the IP address of the corresponding node.
- DB_PORT is the database port. The default port number is 8635.
You can click the instance name to go to the Basic Information page. In the navigation pane on the left, choose Connections. On the displayed page, click the Private Connection tab and obtain the port from the Database Port field in the Basic Information area.
Figure 1 Obtaining the port
- DB_USER is the database user. The default value is rwuser.
- FILE_PATH is the path for storing the root certificate.
- --sslAllowInvalidHostnames: To ensure that the internal communication of the single nodes does not occupy resources such as the user IP address and bandwidth, the single node certificate is generated using the internal management IP address. --sslAllowInvalidHostnames is needed for the SSL connection over private networks.
Command example:
./mongo --host 192.168.xx.xx --port 8635 -u rwuser -p --authenticationDatabase admin --ssl --sslCAFile /tmp/ca.crt --sslAllowInvalidHostnames
Enter the database password when prompted:
Enter password:
- DB_HOST is the private IP address of the instance to be connected.
- Check the connection result. If the following information is displayed, the connection is successful.
replica:PRIMARY>
Unencrypted Connection
If you connect to an instance over an unencrypted connection, disable SSL first. Otherwise, an error is reported. For details about how to disable SSL, see Enabling and Disabling SSL.
- Log in to the ECS.
- Connect to a DDS instance.
Using a private IP address
Example command:
./mongo --host<DB_HOST>--port<DB_PORT>-u<DB_USER>-p --authenticationDatabase admin
Parameter description:
- DB_HOST is the private IP address of the instance to be connected.
On the Instances page, click the instance name. The Basic Information page is displayed. Choose Connections. On the Private Connection tab, obtain the IP address of the corresponding node.
- DB_PORT is the database port. The default port number is 8635.
You can click the instance name to go to the Basic Information page. In the navigation pane on the left, choose Connections. On the displayed page, click the Private Connection tab and obtain the port from the Database Port field in the Basic Information area.
Figure 2 Obtaining the port
- DB_USER is the database user. The default value is rwuser.
Command example:
./mongo --host 192.168.xx.xx --port 8635 -u rwuser -p --authenticationDatabase admin
Enter the database password when prompted:
Enter password:
- DB_HOST is the private IP address of the instance to be connected.
- Check the connection result. If the following information is displayed, the connection is successful.
replica:PRIMARY>
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot