diff options
Diffstat (limited to 'src/mongo/s/shard_key_pattern.cpp')
| -rw-r--r-- | src/mongo/s/shard_key_pattern.cpp | 21 |
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 { |
