tencent cloud

TencentDB for MongoDB

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Strengths
Use Cases
Cluster Architecture
Product Specifications
Features
Regions and AZs
Terms
Service Regions and Service Providers
Purchase Guide
Billing Overview
MongoDB Pricing
Billing Formula
Payment Overdue
Backup Space Billing
Configuration Adjustment Billing
Getting Started
Quickly Creating an Instance
Connecting to a TencentDB for MongoDB Instance
Reading/Writing Database
Operation Guide
Access Management
Instance Management
Node Management
Version Upgrade
Network Configuration
Monitoring
Backup and Rollback
Database Audit
Data Security
SSL Authentication
Log Management
Database Management
Multi-AZ Deployment
Disaster Recovery/Read-Only Instances
Parameter Configuration
Recycle Bin
Task Management
Performance Optimization
Data Migration Guide
Practical Tutorial
Optimizing Indexes to Break Through Read/Write Performance Bottlenecks
Troubleshooting Mongos Load Imbalance in Sharded Cluster
Considerations for Using Shard Clusters
Sample of Reading and Writing Data in MongoDB Instance
Methods for Importing and Exporting Data Based on CVM Connected with MongoDB
What to Do for Errors of Repeated Instance Creation and Deletion of Databases with the Same Names?
Troubleshooting MongoDB Connection Failures
Shard Removal Task: Guide for Confirming the Progress and Troubleshooting Issues
Performance Fine-Tuning
Ops and Development Guide
Development Specifications
Command Support in Sharded Cluster v3.2
Command Support in v3.6
Development Ops
Troubleshooting
Increased Slow Queries
Number of Connections Exceeding Limit
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Backup APIs
Account APIs
Other APIs
Task APIs
Introduction
Data Types
Error Codes
Instance Connection
Shell Connection Sample
PHP Connection Sample
Node.js Connection Sample
Java Connection Sample
Python Connection Sample
Python Read/Write Sample
Go Connection Sample
PHP Reconnection Sample
Product Performance
Test Environment
Test Method
Test Result
FAQs
Cost
Features
Sharded Cluster
Instance
Rollback and Backup
Connection
Data Migration
Others
Service Agreement
Service Level Agreement
Terms of Service
Glossary
Contact Us

Removing a Shard

PDF
Focus Mode
Font Size
Last updated: 2026-02-25 11:24:22

Scenarios

When service traffic changes cause a decrease in instance data and load, you can reduce the shard quantity to release certain database resources and adjust the cluster scale to match the current load. This helps you adjust configurations as needed and avoid resource waste.
Note:
Removing shards will trigger data migration, which may exert a long-term impact on instance load. It is recommended to prioritize the evaluation of directly downgrading mongod node specifications to achieve cost reduction. For specific operations, see Adjusting Mongod Node Specification.
The shard removal feature is currently in public beta. If you need to use this feature, please submit a ticket to apply.

Impacts and Constraints

Before reducing the shard quantity, please carefully read the following key information to ensure that the operation meets expectations and does not impact service stability.
Dimension
Shard Removal
Billing Impact
Yearly/monthly subscription: The remaining balance of the original specifications and the price of the new specifications will be calculated and the difference will be refunded. At the next renewal cycle, charges will be based on the new specifications.
Pay-as-you-go: Charges for the original specifications will be settled, and billing restarts based on the new specifications.
For the detailed billing information, see Configuration Adjustment Billing.
Version Requirement
General Edition: TencentDB for MongoDB 4.0 and later.
Cloud Disk Edition: Shard removal is not supported.
Service Impact
During the operation, no service interruption will occur. Database read and write operations are normal and both automatic and manual backups are supported.
During the operation, you are strictly prohibited from performing any operations that may interfere with data migration, including but not limited to:
Data rollback and instance termination
Configuration adjustment and primary-secondary switch
Connection address modification
Operations on the shards to be removed
Limits and Constraints
Removal order: To-be-removed shards are selected by creation time in descending order.
Space requirement: After removal, the total storage space of the remaining shards must be greater than or equal to 120% of the used space of the cluster. Otherwise, removal is not allowed.
Removal quantity: The number of shards to be removed each time cannot exceed half of the original shard quantity of the cluster. After removal, the number of shards must be greater than or equal to 2.
Note:
Due to kernel limitations, you can only remove one shard at a time in TencentDB for MongoDB 4.0.
Balancer requirement: Before removal, enable the balancer and set the balancing window to control the impact of data migration on services.
Time consumption: Shard removal will trigger data redistribution. This process may be slow, depending on the data volume, balancer settings, and other factors.

Pre-Operation Checklist

No.
Check Item
Check Criteria
Specific Instruction and Operational Guideline
1
Instance status
The instance status is Running.
On the Instance List page, check that the target instance is running normally.
2
Shard quantity
Before removal, the shard quantity must be greater than 2.
This is a prerequisite. If the current number of shards equals 2, removal cannot be performed. Removing shards would result in fewer than 2 shards, which does not meet cluster architecture requirements.
3
Instance expiration time
The expiration time of a yearly/monthly subscription instance must be greater than or equal to 14 days.
In the Configuration Information section on the Instance Details page, view Expiration Time to ensure that the instance has sufficient remaining service time.
4
Storage space after removal
Total storage space of the remaining shards > Current used space of the cluster x 120%
1. In the Specifications section on the Instance Details page, view the total storage space and used space.
2. Calculate the total storage space of the remaining shards, as shown in the example below.
Current total space: 150 GB (3 shards x 50 GB)
Shards to be removed: 1 shard
Space after removal: 100 GB
Currently used: 1.5 GB
Minimum required space: 1.5 GB x 120% = 1.8 GB
Verification: Because 100 GB is greater than 1.8 GB, the check passed.
5
Balancer settings
Ensure that the balancer is enabled. It is recommended to set the balancing window.
1. On the Parameter Settings page in the console, set the openBalance.window parameter to true to enable the balancer.
2. Set off-peak hours as the balancing window by configuring the balance.window parameter to minimize the impact of data migration on services. For specific operations, see Database Parameter Adjustment.
6
Primary shard check
Confirm that the shard to be removed is not the primary shard of any unsharded collection.
1. Connect to the instance using the MongoDB Shell, query the config database by executing getSiblingDB("config").databases.find(), and identify the databases where a to-be-removed shard serves as the primary shard.
Note:
The shard name format is cmgo-xxxxxxxx_n. xxxxxxxx is the unique instance identifier (8 characters) and n is the shard sequence number starting from 0. For example, a 5-shard instance would have shard names ranging from cmgo-xxxxxxxx_0 to cmgo-xxxxxxxx_4. If you need to remove the last shard, you should specify cmgo-xxxxxxxx_4.

db.getSiblingDB("config").databases.find({primary: "cmgo-xxxxxxxx_3"})
2. For each identified database, use the getCollectionNames() method to obtain a complete list of all collections.
db.getSiblingDB("bulk_db_db_77").getCollectionNames()
3. Check the sharding status of each collection by executing db.collection.stats().sharded. If the return value is false (indicating unsharded), you must execute the movePrimary command to move the primary shard of the database containing this collection to another shard. For details, see movePrimary (database command).
Note:
In TencentDB for MongoDB 4.0 and 4.2, after movePrimary is executed, it is necessary to refresh the routing information. Otherwise, read and write operations may be blocked. The refresh method is as follows:
Version 4.0: After executing movePrimary, restart all mongos nodes or execute the flushRouterConfig command on all mongos nodes.
Version 4.2: After executing movePrimary, restart all mongos and mongod nodes or execute the flushRouterConfig command on all mongos and mongod nodes.
db.getSiblingDB("bulk_db_db_77").collection1.stats().sharded

Removing a Shard

2. In the MongoDB drop-down list on the left sidebar, select Shard Instance.
3. Above the Instance List page on the right, select the target region.
4. In the instance list, find the target instance.
5. Click Instance ID to go to the Instance Details page and click the Node Management tab.
6. In the Node Operation drop-down list, select Delete Shard.

7. In the Delete Shard window, learn about the restrictions and conditions for removing shards and refer to the table below to specify the number of shards to be removed.

Parameter Category
Parameter
Example
Description
Basic Instance Information
Instance Name
test-4dot2-XXX
Name of the instance for which the shard quantity is to be reduced.
Expiration Time
2025-04-24 19:23:43
Service expiration time of a yearly/monthly subscription instance.
Instance Architecture
A sharded cluster instance that has 3 shards, each with 4 nodes, among which there is 1 read-only node
Cluster architecture of the instance: sharded cluster instance.
Shard quantity: shard quantity before removal.
Nodes per shard: number of nodes per shard and number of read-only nodes.
Node Specification
2 cores, 4 GB memory, 250 GB storage, and 10 nodes in total
Single shard node specification: including CPU cores, memory, and storage capacity.
Total number of cluster nodes: total number of nodes in the instance before removal (Number of shards x Nodes per shard = Total number of cluster nodes).
Configuration Downgrade
Number of Shards to Be Deleted
2
Specify the number of shards to be removed for the instance.
After specifying the number of shards to be removed, click Check Shards to Be Removed to check whether the conditions for removing shards are met.
Check the number of remaining shards: Ensure that the number of remaining shards is not less than 2 after removal.
Check the storage space: Ensure that the total storage space of the remaining shards after removal is greater than 120% of the currently used space in the cluster.
Check the primary shard information: Check whether the shards to be removed contain any primary shards of databases. If yes, you must manually move them to other shards before proceeding.
Cost Information
Fees
0.92 USD/hour
Pay-as-you-go: The hourly billing rate after shard removal for the instance will be displayed.
Yearly/monthly subscription: The refund amount after the specifications are downgraded will be displayed.
For billing details after configuration adjustments, see Configuration Adjustment Billing.
8. After confirming the details, click OK. If the instance uses yearly/monthly subscription billing, you must pay the price difference between the original and new specifications on the Confirm Product Information page to successfully complete the configuration adjustment.
Note:
If the data volume on the shard node is too large, the balancing window is too small, or there is a jumbo chunk, it will directly cause the shard removal task to take a long time, or even the task will be blocked and fail. For specific troubleshooting and resolution methods, see Shard Removal Task: Guide for Confirming the Progress and Troubleshooting Issues.
9. During task execution, if you need to stop the removal, click Terminate on the Task Management page. After termination, the shard quantity will revert to the original level.

Related APIs

API
Description
Adjusts the cloud database instance configurations
Queries the sales specifications of cloud databases

Appendix: Example of Verifying That the Shard to Be Removed Is Not the Primary Shard of Any Unsharded Collection

1. Query the config database by executing getSiblingDB("config").databases.find(), and identify the databases whose primary shard is the shard to be removed. The following example shows how to query the databases where shard cmgo-xxxxxxxx_3 serves as the primary shard.

mongos> db.getSiblingDB("config").databases.find({primary: "cmgo-xxxxxxxx_3"})
{ "_id" : "bulk_db_db_3", "primary" : "cmgo-xxxxxxxx_3", "partitioned" : false, "version" : { "uuid" : UUID("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"), "timestamp" : Timestamp(1762855003, 5), "lastMod" : 1 } }
{ "_id" : "bulk_db_db_4", "primary" : "cmgo-xxxxxxxx_3", "partitioned" : false, "version" : { "uuid" : UUID("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), "timestamp" : Timestamp(1762855035, 2), "lastMod" : 1 } }
{ "_id" : "bulk_db_db_10", "primary" : "cmgo-xxxxxxxx_3", "partitioned" : false, "version" : { "uuid" : UUID("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), "timestamp" : Timestamp(1762855333, 3), "lastMod" : 1 } }
{ "_id" : "bulk_db_db_14", "primary" : "cmgo-xxxxxxxx_3", "partitioned" : false, "version" : { "uuid" : UUID("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), "timestamp" : Timestamp(1762855462, 30), "lastMod" : 1 } }

2. For each identified database, use the getCollectionNames() method to obtain a complete list of all collections. The following example shows how to query all collections in the database named bulk_db_db_77.

mongos> db.getSiblingDB("bulk_db_db_77").getCollectionNames()
[
"collection_1",
"collection_10",
"collection_11",
"collection_12",
"collection_13",
"collection_14",
"collection_15",
"collection_16",
"collection_17",
"collection_18",
"collection_19",
"collection_2",
"collection_20",
"collection_3",
"collection_4",
"collection_5",
"collection_6",
"collection_7",
"collection_8",
"collection_9"
]

3. Check the sharding status of each collection by executing db.collection.stats().sharded. The following example shows how to query the sharding status of the bulk_db_db_77.collection1 collection. If "sharded" : false is returned, you must use the movePrimary command to move the primary shard of the database containing this collection to another shard.

mongos> db.getSiblingDB("bulk_db_db_77").collection1.stats()
{
"sharded" : false,
"primary" : "cmgo-xxxxxxxx_3",
"ns" : "bulk_db_db_77.collection1",
"count" : 0,
"size" : 0,
"storageSize" : 0,
"totalIndexSize" : 0,
"totalSize" : 0,
"indexSizes" : {

},
"avgObjSize" : 0,
"maxSize" : NumberLong(0),
"nindexes" : 0,
"scaleFactor" : 1,
"nchunks" : 1,
"shards" : {
"cmgo-xxxxxxxx_3" : {
"ns" : "bulk_db_db_77.collection1",
"size" : 0,
"count" : 0,
"numOrphanDocs" : 0,
"storageSize" : 0,
"totalSize" : 0,
"nindexes" : 0,
"totalIndexSize" : 0,
"indexDetails" : {

},
"indexSizes" : {

},
"scaleFactor" : 1,
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1763094536, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"$configTime" : Timestamp(1763094535, 2),
"$topologyTime" : Timestamp(1762853939, 5),
"operationTime" : Timestamp(1763094536, 1)
}
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1763094536, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"operationTime" : Timestamp(1763094536, 1)
}
mongos> db.getSiblingDB("bulk_db_db_77").collection1.stats().sharded
false


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback