Currently, the validation within the ShardKeyPattern class doesn't check that the shard key fields don't have the "$" prefix. So the shardCollection command depends on the index key pattern validation here to prevent a shard key like {"$x": 1} from being used. However, "$**" is a special field name is allowed to bypass this check.
As a result, one can run a shardCollection command with the shard key with {"$**": 1} without getting any error. However, the resulting collection appears to have a number of unexpected behaviors. For example:
- Running a listCollections command would fail with a BadValue error "unknown top level operator: $**. If you have a field name that starts with a '$' symbol, consider using $getField or $setField.".
- Running a {$collStats: {}} aggregation would hit this tassert in QueryPlannerIXSelect.
- causes
-
SERVER-76948 Allow shard key fields to contain DBRefs
- Closed
- is related to
-
SERVER-37803 Test that a wildcard index cannot be used as a shard key index
- Closed
- related to
-
SERVER-77255 Shard key field validation for DBRefs prohibits extra dollar-prefixed fields
- Closed