-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: 8.2.1, 8.0.17, 7.0.30
-
Component/s: None
-
Catalog and Routing
-
Fully Compatible
-
ALL
-
v8.2, v8.0, v7.0
-
CAR Team 2025-09-01, CAR Team 2025-09-15, CAR Team 2025-09-29
-
(copied to CRM)
-
đ„ DDL
-
None
-
None
-
None
-
None
-
None
-
None
ISSUE DESCRIPTION AND IMPACT
Compound wildcard indexes prefixed with the shard key can be incorrectly used as a shard key index to determine which documents to move during chunk migrations, causing some documents to be left behind on the donor shard and resulting in data loss.
When a chunk migration uses a compound wildcard index as a shard key index, all documents that are missing all of the fields covered by that index will remain on the donor shard and wonât be migrated.
If, instead, the compound wildcard index is defined with a descending wildcard field (for example, {skey: 1, âa.$**â: -1}), the chunk migration also leaves behind documents whose shard key is equal to the chunkâs min boundary.
Independently, if the range deleter uses a compound wildcard index as a shard key index, all the documents lacking all index fields wonât get removed, leaving dangling orphans on the donor shard.
DIAGNOSIS AND AFFECTED VERSIONS
Sharded collections with compound wildcard indexes prefixed with the shard key may be affected on versions MongoDB 7.0.0-7.0.30, MongoDB 8.0.0-8.0.17, and MongoDB 8.2.0-8.2.1.
A sharded cluster may have been impacted by this issue if all of the following conditions are true (now or at any point in the past) for a sharded collection:
- Your sharded cluster has two or more shards;
- The collection has a compound wildcard index where the shard key appears first in the index definitionâfor example, if your shard key is {skey: 1}, an affected index would look like {skey: 1, "a.$**": 1} (the $** indicates a wildcard component);
- The balancer was active for that collection, or chunks were moved manually; and
- Either:
- The collection contains documents missing all fields defined in the compound wildcard index, or
- The compound wildcard index is in descending order (e.g., {skey: 1, âa.$**â: -1})
The following steps explain how to verify that a sharded collection has a compound wildcard index prefixed with the shard key:
- List the collectionâs indexes and review their key patterns. In mongosh, run the following to list all indexes for that collection: db.getSiblingDB("<db>").getCollection("<collection>").getIndexes().
- Identify compound wildcard indexes: look for an index key that includes $** plus at least one additional field (for example, {skey: 1, "a.$**": 1}).
- Confirm the shard key prefix: the shard key field(s) must appear first in the index key pattern, in the same order as the shard key.
- If these conditions are met, the index is a compound wildcard index prefixed with the shard key.
REMEDIATION AND WORKAROUNDS
- Upgrade to a fixed version and keep the balancer disabled until all the remediation steps are completed. The fixed versions are MongoDB 7.0.31+ (i.e., any 7.0.Y that includes the fix), 8.0.18+, or 8.2.2+.
- If dangling orphans are suspected (e.g., due to prior migrations using a compound wildcard index), use the provided remediation procedures/scripts to detect, recover, and clean up dangling orphans. Note that newer versions may surface such cases during chunk migrations due to
SERVER-110953. - Because this fix removes compound wildcard indexes from the set of indexes that can support a shard key, some sharded collections might no longer have a valid shard key index after upgrade. Therefore, youâll need to verify that every sharded collection has a valid shard key index. If a collection reports a MissingShardKeyIndex in the checkMetadataConsistency command, youâll need to create a valid shard key index via a mongos connection. Additionally, if range deletions are blocked on shards that do not own chunks (log message 23765 âUnable to find range shard key indexâ), create the shard key index through direct shard connections on those shards to unblock the range deleter.
- Finally, re-enable the balancer if it was enabled before the upgrade.
Interim workarounds if you cannot upgrade immediately, you can either:
- Disable the balancer at the cluster level and stop the range deleter on every node in the cluster by setting the `disableResumableRangeDeleter` server parameter to âtrueâ for all sharded collections that have a compound wildcard index prefixed with the shard key, OR
- Drop all the compound wildcard indexes that are prefixed with the shard key.
- is related to
-
SERVER-109929 shardCollection/reshardCollection must attempt to create a shardkey when a multikey/wildcard index exists on the shard key field
-
- Closed
-
-
SERVER-110953 Check no orphaned document is present on a recipient shard before starting cloning a range
-
- Closed
-
- related to
-
SERVER-112358 [v7.0] Resharding doesn't create a shard key index if a multikey index exists prefixed by the shard key
-
- Needs Scheduling
-
-
SERVER-89308 Create query property tester
-
- Closed
-
-
SERVER-112793 Remove metrics for compound wildcard index prefixed by shard key once 9.0 branches out
-
- Backlog
-
-
SERVER-109796 Investigate shardKeyIndex scan incorrect behavior with a compound wildcard index
-
- Closed
-
-
SERVER-109946 IndexDescriptor::isSparse should return true for wildcard indexes
-
- Closed
-
-
SERVER-112792 Report existance of compound wildcard indexes prefixed by the shard key
-
- Closed
-