summaryrefslogtreecommitdiff
path: root/src/mongo/s/shard_key_pattern.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/s/shard_key_pattern.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/s/shard_key_pattern.cpp')
-rw-r--r--src/mongo/s/shard_key_pattern.cpp21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/mongo/s/shard_key_pattern.cpp b/src/mongo/s/shard_key_pattern.cpp
index 9e6f3244dcd..c8fb1b7a84c 100644
--- a/src/mongo/s/shard_key_pattern.cpp
+++ b/src/mongo/s/shard_key_pattern.cpp
@@ -33,7 +33,6 @@
#include <vector>
-#include "mongo/bson/simple_bsonelement_comparator.h"
#include "mongo/db/field_ref.h"
#include "mongo/db/field_ref_set.h"
#include "mongo/db/hasher.h"
@@ -86,20 +85,10 @@ std::vector<std::unique_ptr<FieldRef>> parseShardKeyPattern(const BSONObj& keyPa
// Empty parts of the path, ".."?
for (size_t i = 0; i < newFieldRef->numParts(); ++i) {
- const StringData part = newFieldRef->getPart(i);
-
uassert(ErrorCodes::BadValue,
str::stream() << "Field " << patternEl.fieldNameStringData()
<< " contains empty parts",
- !part.empty());
-
- // Reject a shard key that has a field name that starts with '$' or contains parts that
- // start with '$' unless the part is a DBRef (i.e. is equal to '$id', '$db' or '$ref').
- uassert(ErrorCodes::BadValue,
- str::stream() << "Field " << patternEl.fieldNameStringData()
- << " contains parts that start with '$'",
- !part.startsWith("$") ||
- (i != 0 && (part == "$db" || part == "$id" || part == "$ref")));
+ !newFieldRef->getPart(i).empty());
}
// Numeric and ascending (1.0), or "hashed" with exactly hashed field.
@@ -299,7 +288,7 @@ bool ShardKeyPattern::isShardKey(const BSONObj& shardKey) const {
}
bool ShardKeyPattern::isExtendedBy(const ShardKeyPattern& newShardKeyPattern) const {
- return toBSON().isPrefixOf(newShardKeyPattern.toBSON(), SimpleBSONElementComparator::kInstance);
+ return toBSON().isFieldNamePrefixOf(newShardKeyPattern.toBSON());
}
BSONObj ShardKeyPattern::normalizeShardKey(const BSONObj& shardKey) const {
@@ -555,12 +544,12 @@ BSONObj ShardKeyPattern::extractShardKeyFromQuery(const CanonicalQuery& query) c
return keyBuilder.obj();
}
-bool ShardKeyPattern::isIndexUniquenessCompatible(const BSONObj& indexPattern) const {
- if (!indexPattern.isEmpty() && indexPattern.firstElementFieldName() == kIdField) {
+bool ShardKeyPattern::isUniqueIndexCompatible(const BSONObj& uniqueIndexPattern) const {
+ if (!uniqueIndexPattern.isEmpty() && uniqueIndexPattern.firstElementFieldName() == kIdField) {
return true;
}
- return _keyPattern.toBSON().isFieldNamePrefixOf(indexPattern);
+ return _keyPattern.toBSON().isFieldNamePrefixOf(uniqueIndexPattern);
}
BoundList ShardKeyPattern::flattenBounds(const IndexBounds& indexBounds) const {