[SERVER-74124] Disallow sharding with wildcard shard key pattern Created: 16/Feb/23  Updated: 29/Oct/23  Resolved: 23/Feb/23

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 4.2.0, 4.4.0, 5.0.0, 6.0.0, 6.3.0-rc0
Fix Version/s: 7.0.0-rc0, 6.0.5, 6.3.0-rc1, 4.4.20, 5.0.16

Type: Bug Priority: Major - P3
Reporter: Cheahuychou Mao Assignee: Cheahuychou Mao
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
causes SERVER-76948 Allow shard key fields to contain DBRefs Closed
Related
related to SERVER-77255 Shard key field validation for DBRefs... Closed
is related to SERVER-37803 Test that a wildcard index cannot be ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.3, v6.0, v5.0, v4.4, v4.2
Sprint: Sharding NYC 2023-03-06
Participants:

 Description   

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.


 Comments   
Comment by Githook User [ 06/Mar/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Skip reshardCollection test case in sharding_last_lts_mongos_and_mixed_shards suite
Branch: v5.0
https://github.com/mongodb/mongo/commit/2a5fd686d1f2721835e5a53ab9e6f6b8ab074475

Comment by Githook User [ 28/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Use StringData::startsWith instead of StringData::find to check for '$'

(cherry picked from commit fbb8024e67150305f9fc94b3a5fe57f6b8403de3)
Branch: v4.4
https://github.com/mongodb/mongo/commit/a8a56aa7d8b4f2719bd8313bc4f6e06e6bb6a626

Comment by Githook User [ 28/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Disallow shard key pattern with fields that have parts that start with '$'

(cherry picked from commit 7137269)
Branch: v4.4
https://github.com/mongodb/mongo/commit/ccf7b6c7cda1a93e1c87fb30663c8c6a4c093f60

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Use StringData::startsWith instead of StringData::find to check for '$'

(cherry picked from commit fbb8024e67150305f9fc94b3a5fe57f6b8403de3)
Branch: v5.0
https://github.com/mongodb/mongo/commit/cbfb04f1a151a7da2a71125286a7e3bd20cf2217

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Disallow shard key pattern with fields that have parts that start with '$'

(cherry picked from commit 71372698d18785a374aa09bdd646d3c5dc2f227a)
Branch: v5.0
https://github.com/mongodb/mongo/commit/f22bd2c1958f7d79e62b1b0f213ce5318c597bbb

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Use StringData::startsWith instead of StringData::find to check for '$'

(cherry picked from commit fbb8024e67150305f9fc94b3a5fe57f6b8403de3)
Branch: v6.3
https://github.com/mongodb/mongo/commit/7e54d2db7397fcd7f61abe03fabb7f9a2104fbb2

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Disallow shard key pattern with fields that have parts that start with '$'

(cherry picked from commit 71372698d18785a374aa09bdd646d3c5dc2f227a)
Branch: v6.3
https://github.com/mongodb/mongo/commit/8f3946c68aa48d85472ff005a4bd03d9df2ba4b9

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Use StringData::startsWith instead of StringData::find to check for '$'

(cherry picked from commit fbb8024e67150305f9fc94b3a5fe57f6b8403de3)
Branch: v6.0
https://github.com/mongodb/mongo/commit/a8c8ebde234867480ce829a0076e91b9a0f61591

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Disallow shard key pattern with fields that have parts that start with '$'

(cherry picked from commit 71372698d18785a374aa09bdd646d3c5dc2f227a)
Branch: v6.0
https://github.com/mongodb/mongo/commit/d21dedda973c25da704c9ad416d20bdcf384892f

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Use StringData::startsWith instead of StringData::find to check for '$'
Branch: master
https://github.com/mongodb/mongo/commit/fbb8024e67150305f9fc94b3a5fe57f6b8403de3

Comment by Githook User [ 23/Feb/23 ]

Author:

{'name': 'Cheahuychou Mao', 'email': 'mao.cheahuychou@gmail.com', 'username': 'cheahuychou'}

Message: SERVER-74124 Disallow shard key pattern with fields that have parts that start with '$'
Branch: master
https://github.com/mongodb/mongo/commit/71372698d18785a374aa09bdd646d3c5dc2f227a

Generated at Thu Feb 08 06:26:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.