To read the oplog of a specific shard node—for example, to implement data synchronization or incremental backups—you need a direct connection endpoint for that shard. By default, you connect to an ApsaraDB for MongoDB sharded cluster through a Mongos node, which is sufficient for most read and write workloads but does not expose individual shard oplogs.
Background information
An ApsaraDB for MongoDB sharded cluster instance consists of three components: Mongos, Shard, and Configserver. You can select the number and configuration of shard components to create sharded cluster instances with different performance levels.
Prerequisites
Before you begin, ensure that you have:
A sharded cluster instance
The MongoDB protocol configured on the instance
Usage notes
After you apply for a shard endpoint, the system creates endpoints for the primary, secondary, and read-only nodes in the shard. Each endpoint requires one IP address. Make sure you have enough IP addresses available.
The network type of the shard endpoint must match the network type of the Mongos node.
A shard endpoint cannot be modified after it is created.
This topic describes how to apply for a private endpoint. To access the shard over the Internet, apply for a private endpoint first, set an account and password, and then apply for a public endpoint. For more information, see Apply for a public endpoint for an instance.
If your instance uses local disks, you can apply for a direct connection account when you apply for the shard endpoint. If your instance uses cloud disks, you must first create a direct connection account on the Account Management page before you apply for the shard endpoint.
You can apply for an endpoint only for a shard in a sharded cluster instance.
Apply for a shard endpoint
The steps differ depending on whether your instance uses cloud disks or local disks. Identify your disk type, then follow the corresponding procedure.
Instances that use cloud disks
Applying for a shard endpoint on a cloud disk instance causes existing connections to experience transient connections. Make sure your application has an automatic reconnection mechanism. Perform this operation during off-peak hours to minimize impact.
You only need to create a shard account the first time you apply for a shard endpoint on this instance. Skip Step 1 for subsequent applications.
Step 1: Create a shard account
Go to the Sharded Cluster Instances page. In the upper-left corner, select a resource group and a region, then click the ID of the target instance.
In the navigation pane, click Accounts.
Click Create Account.
In the Create Account(Only shards are supported.) panel, set the following parameters:
Parameter Description Account Name Must start with a lowercase letter. Can contain lowercase letters, digits, and underscores (_). Must be 4–16 characters in length. Keywords are not allowed. The account has read-only permissions. Account Password Must be 8–32 characters in length and include at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ( !@#$%^&*()_+-=). To reset the password later, see Reset a password.Confirm Password Enter the password again. Click OK.
Step 2: Create a shard endpoint
In the navigation pane, click Database Connections.
In the Internal Connections section, click Create-Shard-Cs-Connections.
In the Create-Shard-Cs-Connections panel, set the following parameters:
Parameter Description Node Type Fixed to Shard. Select Node ID Select the ID of the shard node for which you want to create an endpoint. Click OK.
Wait for the instance status to change from Creating Network Connection to Running.
In the Internal Connections section, view the newly created endpoint.
Instances that use local disks
Alternatively, go to the Basic Information page of the instance, find the Shard List section, and click Add Shard. Enable the direct connection option and apply for an endpoint in the Apply For Shard Direct Connection Endpoint section.
You only need to set an account name and password the first time you apply for a shard or Configserver node endpoint on this instance. For subsequent applications, these fields are not required.
Go to the Sharded Cluster Instances page. In the upper-left corner, select a resource group and a region, then click the ID of the target instance.
In the navigation pane, click Database Connections.
In the Internal Connections section, click Create-Shard-Cs-Connections.
In the Create-Shard-Cs-Connections panel, set the following parameters:
Parameter Description Node Type Fixed to Shard. Select Node ID Select the ID of the shard node for which you want to create an endpoint. Account Name Must start with a lowercase letter. Can contain lowercase letters, digits, and underscores (_). Must be 4–16 characters in length. Keywords are not allowed. The account has read-only permissions. Account Password Must be 8–32 characters in length and include at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters ( !@#$%^&*()_+-=). To reset the password later, see Reset a password.Confirm Password Enter the password again. Click OK.
Wait for the instance status to change from Creating Network Connection to Running.
In the Internal Connections section, view the newly created endpoint.
What's next
Connect to the shard node using the endpoint you just created to read its oplog or perform direct shard operations.
If you no longer need the shard endpoint, release it. For more information, see Release the endpoint of a shard or Configserver node.