tencent cloud

Data Transfer Service

Creating Data Subscription for MongoDB

Baixar
Modo Foco
Tamanho da Fonte
Última atualização: 2026-12-01 18:06:34
Traduzido e Verificado por IA

Overview

This scenario describes how to use DTS to create a data subscription task for TencentDB for MongoDB.

Prerequisites

The TencentDB instance to be subscribed to is ready.
We recommend that you create a read-only account on the source instance. You can refer to the following syntax. If the source database is TencentDB for MongoDB, you can also create a read-only account in the MongoDB console.
# Create a read-only account for all instances
use admin
db.createUser({
user: "username",  
pwd: "password",  
roles:[    
{role: "readAnyDatabase",db: "admin"}  
]
})

# Create a read-only account for a specified database
use admin
db.createUser({
user: "username",  
pwd: "password",  
roles:[    
{role: "read",db: "name of the specified database"}
]
})

Subscription Configuration Steps

1. Log in to the DTS console, select Data Subscription in the left sidebar, and click Create Subscription.
2. On the Create Subscription page, select the corresponding configuration, and click Buy Now.
Parameter Name
Configuration Methods
Billing Mode
Yearly/Monthly subscription and pay-as-you-go are supported. For billing details, see DTS Billing Mode.
Region
The region of the DTS subscription service must be consistent with the region of the source database instance.
Database
Select MongoDB.
Edition
Default: Kafka.
Tag
Specify tags for the data subscription service. This is optional.
Subscribed Instance Name
Naming after creation: After a data subscription service is created, the system randomly assigns an instance name, and users can modify the name later.
Name it now: Enter the data subscription service name directly in the input box below.
Auto-renewal
Select this option. If not selected, pay attention to service expiration warnings. For details, see Overdue Payment.
Purchase Duration
The longer the purchase duration, the more discounts you enjoy.
Purchase Quantity
A single purchase supports up to 10 tasks.
3. After successful purchase, return to the data subscription list, select the task just purchased, and click Configure Subscription in the Operation column.


4. On the Configure Database Subscription page, configure the source database information, click Test Connectivity, and after it passes, click Save and Next.
Access type: Currently, only cloud database is supported.
Cloud database instance: Select the cloud database instance ID.
Database account/password: Add the account and password of the subscription instance. The account must have read-only permissions.

5. On the Subscription Type and Object Selection page, select the subscription parameters, and click Save and Next.


Parameter
Description
Subscription type
Defaults to Change Stream and cannot be modified.
Subscription data format
Currently, only the JSON format is supported.
Subscription level
Subscription level, including instance, database, and collection.
All instances: Subscribe to data from all instances.
Database: Subscribe to database-level data. After selection, you can select only one database in the task settings below.
Collection: Subscribe to collection-level data. After selection, you can select only one collection in the task settings below.
Task Configuration
After Subscription Level is set to Database or Collection, configuration is required. Select the databases or collections to subscribe to.
Only one database or one collection can be selected.
Output aggregation settings
After selected, the execution order of aggregation pipelines is determined by the configuration order on the page. For more information about aggregation pipelines and usage examples, see the MongoDB official documentation.
Number of Topic partitions
Set the number of Topic partitions. Increasing the number of partitions can improve data write and consumption speed. A single partition can guarantee message order, while multiple partitions cannot. If you have strict requirements on message consumption order, set the number of partitions to 1.
Topic partition policy
When the number of Topic partitions is not 1, you can set a partitioning policy.
Partition by collection name: Partition the subscription data from the source database by collection name. After this setting, data with the same collection name will be written to the same Kafka partition.
Custom partition policy: First, match the database names and collection names in the subscription data using regular expressions. Then, partition the matched data by collection name or by collection name + ObjectId.
6. On the Pre-verification page, the pre-verification task is expected to run for 2–3 minutes. After the pre-verification is passed, click Start to complete the configuration of the data subscription task.
Note:
If the check fails, see Handling Methods for Check Failures to make corrections and perform the check again.

7. The subscription task is being initialized and is expected to run for 3-4 minutes. After successful initialization, it enters the Running state.

Subsequent Operation Steps

After the subscription task is created, you need to consume the data. For details, see Consuming MongoDB Subscription Data.
1. Add a consumer group.
Data consumption in data subscription depends on Kafka consumer groups, so you need to create a consumer group before consuming data. Data Subscription for Kafka allows you to create multiple consumer groups (up to 10 consumer groups per subscription task) for multi-point consumption.
2. Consume the subscription data.
After the subscription task enters the Running state, you can start consuming data. Kafka consumption requires password authentication. For details, see the Demo in the link above. We provide Demo code in multiple languages and explain the main consumption process and key data structures.

Ajuda e Suporte

Esta página foi útil?

comentários