summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-10-14 12:19:34 -0400
committerDavid Storch <david.storch@10gen.com>2016-10-14 16:47:12 -0400
commit8dbff3e5ce8df22b262f989f46dfc3c322fa7218 (patch)
tree35acdbac3adcf41705572247ce6527ad79b9822d /src/mongo/db/catalog
parentc1a3bd37d4eb3af247f10398576dcfb5343e81e2 (diff)
downloadmongo-8dbff3e5ce8df22b262f989f46dfc3c322fa7218.tar.gz
SERVER-26571 ignore 'create' field during collection options parsing
This ensures that we can handle collection metadata created on version 2.4 or earlier.
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/collection_options.cpp13
-rw-r--r--src/mongo/db/catalog/collection_options_test.cpp18
2 files changed, 26 insertions, 5 deletions
diff --git a/src/mongo/db/catalog/collection_options.cpp b/src/mongo/db/catalog/collection_options.cpp
index 786bffad84d..91cf5bbdc9d 100644
--- a/src/mongo/db/catalog/collection_options.cpp
+++ b/src/mongo/db/catalog/collection_options.cpp
@@ -86,6 +86,13 @@ Status checkStorageEngineOptions(const BSONElement& elem) {
return Status::OK();
}
+// These are collection creation options which are either created by other versions and no longer
+// used, or handled elsewhere. If we encounter a field which CollectionOptions doesn't know about,
+// parsing the options should fail unless we find the field name in this whitelist.
+const std::set<StringData> collectionOptionsWhitelist{
+ "create"_sd, "maxTimeMS"_sd, "writeConcern"_sd,
+};
+
} // namespace
void CollectionOptions::reset() {
@@ -245,11 +252,7 @@ Status CollectionOptions::parse(const BSONObj& options) {
}
pipeline = e.Obj().getOwned();
- } else if (fieldName == "writeConcern") {
- continue;
- } else if (fieldName == "maxTimeMS") {
- continue;
- } else {
+ } else if (collectionOptionsWhitelist.find(fieldName) == collectionOptionsWhitelist.end()) {
return Status(ErrorCodes::InvalidOptions,
str::stream() << "The field '" << fieldName
<< "' is not a valid collection option. Options: "
diff --git a/src/mongo/db/catalog/collection_options_test.cpp b/src/mongo/db/catalog/collection_options_test.cpp
index dd384f4d703..083d237ae19 100644
--- a/src/mongo/db/catalog/collection_options_test.cpp
+++ b/src/mongo/db/catalog/collection_options_test.cpp
@@ -269,4 +269,22 @@ TEST(CollectionOptions, UnknownTopLevelOptionFailsToParse) {
ASSERT_NOT_OK(status);
ASSERT_EQ(status.code(), ErrorCodes::InvalidOptions);
}
+
+TEST(CollectionOptions, CreateWhitelistedOptionIgnored) {
+ CollectionOptions options;
+ auto status = options.parse(fromjson("{create: 1}"));
+ ASSERT_OK(status);
+}
+
+TEST(CollectionOptions, MaxTimeMSWhitelistedOptionIgnored) {
+ CollectionOptions options;
+ auto status = options.parse(fromjson("{maxTimeMS: 1}"));
+ ASSERT_OK(status);
+}
+
+TEST(CollectionOptions, WriteConcernWhitelistedOptionIgnored) {
+ CollectionOptions options;
+ auto status = options.parse(fromjson("{writeConcern: 1}"));
+ ASSERT_OK(status);
+}
} // namespace mongo