Create a MongoDB Data Source
Add a MongoDB data source to NineData. You can then use it for Database DevOps, backup and restore, data replication, database comparison, and other supported features. This guide covers MongoDB deployment architecture, connection mode, read preference, credentials, environment settings, SSL settings, and the connection test.
Before you begin
The server IP address of NineData has been added to the data source allowlist. The server IP address can be viewed by selecting the target region in Access Region on the Create Datasource page.

Make sure you have available data source quota; otherwise, the data source cannot be added. You can quickly check your remaining quota at the top-right corner of the NineData console.

Procedure
Log in to the NineData Console.
On the left navigation pane, click Datasource > Datasource.
- Click Datasource tab, and click Create Datasource on the page. In the popup window for selecting the data source type, choose Database > (the type of data source to be added), and configure the parameters based on the table below on the Create Datasource page.tip
If you make a mistake during the operation, you can click the
icon at the top of the Create Datasource page to make a new selection.
Configure the data source parameters:
Parameter Description Name Enter a data source name. Use a meaningful name so you can find and manage it later. Architecture Type Select the MongoDB deployment architecture. - Standalone: Enter the connection address and port of the standalone MongoDB database.
- Replica Set: Enter the connection address and port of the primary node and replica nodes. Click Add to add multiple connection address fields.
- Shard Cluster: Enter the connection address and port of the mongos nodes. For a stable connection, enter all mongos nodes. Click Add to add multiple connection address fields.
Connection Select how NineData connects to the data source. Supported methods are IP Address, Gateway, and SSH Tunnel. - IP Address: Connect through the public network address.
- Gateway: Use a NineData gateway for private-network access. Connect the host that runs the data source first. For instructions, see Add Gateway.
- SSH Tunnel: Connect through an SSH tunnel.
- IP Address: Connect through the public network address.
- SSH Tunnel: Connect through an SSH tunnel.
Configuration items when Connection is IP Address Host: The public network connection address and port of the data source. Configuration items when Connection is Gateway - Gateway: Select the NineData gateway installed on the host where the data source is located.
- Host: Enter localhost if the data source is on the same host as the gateway, or enter the internal IP address of the host where the data source is located.
Configuration items when Connection is SSH Tunnel - SSH Host: Enter the public IP address or domain name and SSH port of the server where the target data source is located. The default SSH port is 22.
- SSH Authentication Method: Select the SSH authentication method.
- Password: Connect with SSH Username and Password.
- SSH Username: Enter the login username of the server where the target data source is located.
- Password: Enter the login password of the server where the target data source is located.
- Key (recommended): Connect with SSH Username and Key File.
- SSH Username: Enter the login username of the server where the target data source is located.
- Key File: Click Upload to upload the private key file, which is a key file without a suffix. If you have not created one yet, see Generate SSH Tunnel Key File.
- Password: Enter the password set when the key file was generated. If no password was set during key generation, leave this field blank.
Note: After configuring SSH, click Connection Test to test the tunnel. Possible results: - Password: Connect with SSH Username and Password.
- Connection Successfully: The SSH tunnel is established.
- Error message: The connection failed. Troubleshoot the cause based on the error message and try again.
- Host: Enter localhost if the data source is on the same host as the SSH server, or enter the internal IP address of the host where the data source is located.
Architecture Type Select the MongoDB deployment architecture type. - Standalone: Standalone deployment. Only one connection address and port are required.
- Replica Set: Replica set deployment. A replica set usually includes one primary node and multiple secondary nodes. Click Add below Host to enter multiple node addresses and ports.
- Shard Cluster: Sharded cluster deployment. A sharded cluster consists of one or more mongos nodes. Click Add below Host to enter multiple mongos addresses and ports.
Read Preference Optional when Architecture Type is Replica Set. Configure which node receives read traffic. - Default: Uses the default configuration and sends read traffic to the Primary node.
- Primary: Sends read traffic to the Primary node.
- Primary Preferred: Sends read traffic to the Primary node when it is available. Otherwise, sends read traffic to another available node.
- Secondary: Sends read traffic to the Secondary node.
- Secondary Preferred: Sends read traffic to the Secondary node when it is available. Otherwise, sends read traffic to another available node.
- Nearest: Selects the best available node and sends read traffic to that node.
Authentication DB The name of the authentication database to which your account belongs, default is admin.DB Account The username of the data source. DB Password The password of the data source. Access Region Select the region closest to your data source location to effectively reduce network latency. Environment Choose based on the business purpose of the data source, as an environmental identifier for the data source. Default provides PROD and DEV environments, and supports you to create a custom environment.
Note: Under the organization mode, the database environment can also be applied to permission policy management, for example, the default Prod Admin role only supports access to data sources in the PROD environment and cannot access data sources in other environments. For more information, see Manage Roles.SSL Choose whether to use SSL encryption to access the data source. If the data source requires SSL-encrypted connections, enable this option; otherwise, the connection fails. For SSL configuration methods, see the official documentation: Configure MongoDB Encrypted Connection. After you configure all parameters, click Connection Test next to Create Datasource to test connectivity. When Connection Successfully is displayed, click Create Datasource to create the data source. Otherwise, review the connection settings and run the test again.
Result
After the connection test succeeds and you create the data source, it appears in the data source list. You can use it in NineData features that support MongoDB.
Appendix: Add NineData IP addresses to the MongoDB database whitelist
When you add a data source located in On-Premise/Other Cloud, add the NineData service IP address to the MongoDB database whitelist so NineData can access the database.
The following example uses MongoDB 5.0.
Connect to MongoDB using a user with root privileges, and create or update an account for NineData access as needed.
Create a new account: Create an account for NineData access and grant the required role permissions.
db.createUser{
user: "<account name>",
pwd: "<password>",
roles: [
{ role: "<role name>", db: "<database name>" },
],
authenticationRestrictions: [
{
clientSource: ["<NineData service IP address>"],
serverAddress: ["<MongoDB server IP address>"]
},
...
]
}Existing account: Add the NineData IP address to the whitelist of an existing account and grant the required role permissions.
db.updateUser(
"<account name>",
{
roles : [
{ role: "<role name>", db: "<database name>" },
...
],
pwd: "<password>",
authenticationRestrictions: [
{
clientSource: ["<NineData service IP address>"],
serverAddress: ["<MongoDB server IP address>"]
},
...
]
)
Use this account to add the MongoDB data source in the NineData console.