summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorJames Wahlin <james@mongodb.com>2018-11-06 16:18:20 -0500
committerJames Wahlin <james@mongodb.com>2018-11-16 14:17:51 -0500
commit410656e971aff8f491a87337a17d04bd866389ba (patch)
treef369934d0fc7b2b89095d2c77df1ecd460bc1ddf /src/mongo/bson
parent63e43f1bb47f7bddf3dc37ad03a2bbee6d2a9423 (diff)
downloadmongo-410656e971aff8f491a87337a17d04bd866389ba.tar.gz
SERVER-37124 Disambiguate DuplicateKey error and return keyPattern details in errorInfo object
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/util/bson_check.h6
-rw-r--r--src/mongo/bson/util/bson_check_test.cpp5
2 files changed, 6 insertions, 5 deletions
diff --git a/src/mongo/bson/util/bson_check.h b/src/mongo/bson/util/bson_check.h
index 250256208ba..ba9407353cf 100644
--- a/src/mongo/bson/util/bson_check.h
+++ b/src/mongo/bson/util/bson_check.h
@@ -43,8 +43,8 @@ namespace mongo {
* Confirms that obj only contains field names where allowed(name) returns true,
* and that no field name occurs multiple times.
*
- * On failure, returns BadValue and a message naming the unexpected field or DuplicateKey and a
- * message naming the repeated field. "objectName" is included in the message, for reporting
+ * On failure, returns BadValue and a message naming the unexpected field or error code 51000 with
+ * a message naming a repeated field. "objectName" is included in the message, for reporting
* purposes.
*/
template <typename Condition>
@@ -65,7 +65,7 @@ Status bsonCheckOnlyHasFieldsImpl(StringData objectName,
if (!seenBefore) {
seenBefore = true;
} else {
- return Status(ErrorCodes::DuplicateKey,
+ return Status(ErrorCodes::Error(51000),
str::stream() << "Field " << name << " appears multiple times in "
<< objectName);
}
diff --git a/src/mongo/bson/util/bson_check_test.cpp b/src/mongo/bson/util/bson_check_test.cpp
index 6c2fa1e0ca7..955af664a21 100644
--- a/src/mongo/bson/util/bson_check_test.cpp
+++ b/src/mongo/bson/util/bson_check_test.cpp
@@ -77,9 +77,10 @@ TEST(BsonCheck, CheckHasOnlyLegalFields) {
}
TEST(BsonCheck, CheckNoDuplicates) {
- ASSERT_EQUALS(ErrorCodes::DuplicateKey,
+ ASSERT_EQUALS(51000,
bsonCheckOnlyHasFields(
- "", BSON("aField" << 1 << "anotherField" << 2 << "aField" << 3), legals));
+ "", BSON("aField" << 1 << "anotherField" << 2 << "aField" << 3), legals)
+ .code());
}
} // namespace