summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/dbcommands.cpp
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2021-01-29 21:38:43 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-08 17:46:17 +0000
commit0963c63a150d99713efbc5ff5221dc34c56718c8 (patch)
treedab1e777621b902ce8d4b51339b01464801038ac /src/mongo/db/commands/dbcommands.cpp
parent7d63d668f001f63672905e8d5f63275c09ba84cd (diff)
downloadmongo-0963c63a150d99713efbc5ff5221dc34c56718c8.tar.gz
SERVER-54018 Restrict metadata and time fields to top-level fields
Diffstat (limited to 'src/mongo/db/commands/dbcommands.cpp')
-rw-r--r--src/mongo/db/commands/dbcommands.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index ba09b7ab525..86b13499dda 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -406,6 +406,18 @@ public:
timeseriesNotAllowedWith("pipeline"),
!cmd.getPipeline());
+ auto hasDot = [](StringData field) -> bool {
+ return field.find('.') != std::string::npos;
+ };
+ auto mustBeTopLevel = [&cmd](StringData field) -> std::string {
+ return str::stream()
+ << cmd.getNamespace() << ": '" << field << "' must be a top-level field "
+ << "and not contain a '.'";
+ };
+ uassert(ErrorCodes::InvalidOptions,
+ mustBeTopLevel("timeField"),
+ !hasDot(timeseries->getTimeField()));
+
if (auto metaField = timeseries->getMetaField()) {
uassert(ErrorCodes::InvalidOptions,
"'metaField' cannot be \"_id\"",
@@ -413,6 +425,9 @@ public:
uassert(ErrorCodes::InvalidOptions,
"'metaField' cannot be the same as 'timeField'",
*metaField != timeseries->getTimeField());
+ uassert(ErrorCodes::InvalidOptions,
+ mustBeTopLevel("metaField"),
+ !hasDot(*metaField));
}
}