summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuhong Zhang <yuhong.zhang@mongodb.com>2022-12-15 14:58:10 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-03 23:29:44 +0000
commit3dc6cd2613648179059128a966ed887475f34290 (patch)
treefbae4ca9a0710947c95127226c51bd8611ef4890
parentf058a17e0cf5a8591993d928e89e778b5b4ca3b7 (diff)
downloadmongo-3dc6cd2613648179059128a966ed887475f34290.tar.gz
SERVER-70139 Check a view's property before returning it as a time-series collection in the `listCollections` result
(cherry picked from commit 6fc43f3993103d5575cf798c829db59b35170f2e)
-rw-r--r--src/mongo/db/commands/list_collections.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index eb465cf9a9b..6d42598684e 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -169,9 +169,7 @@ BSONObj buildViewBson(const ViewDefinition& view, bool nameOnly) {
return b.obj();
}
-BSONObj buildTimeseriesBson(OperationContext* opCtx,
- const CollectionPtr& collection,
- bool nameOnly) {
+BSONObj buildTimeseriesBson(const CollectionPtr& collection, bool nameOnly) {
invariant(collection);
BSONObjBuilder builder;
@@ -382,8 +380,7 @@ public:
if (auto bucketsCollection = CollectionCatalog::get(opCtx)
->lookupCollectionByNamespace(
opCtx, view->viewOn())) {
- return buildTimeseriesBson(
- opCtx, bucketsCollection, nameOnly);
+ return buildTimeseriesBson(bucketsCollection, nameOnly);
} else {
// The buckets collection does not exist, so the time-series
// view will be appended when we iterate through the view
@@ -402,21 +399,22 @@ public:
} else {
auto perCollectionWork = [&](const CollectionPtr& collection) {
if (collection && collection->getTimeseriesOptions() &&
- !collection->ns().isDropPendingNamespace() &&
- catalog->lookupViewWithoutValidatingDurable(
- opCtx, collection->ns().getTimeseriesViewNamespace()) &&
- (!authorizedCollections ||
- as->isAuthorizedForAnyActionOnResource(
- ResourcePattern::forExactNamespace(
- collection->ns().getTimeseriesViewNamespace())))) {
- // The time-series view for this buckets namespace exists, so add it
- // here while we have the collection options.
- _addWorkingSetMember(
- opCtx,
- buildTimeseriesBson(opCtx, collection, nameOnly),
- matcher.get(),
- ws.get(),
- root.get());
+ !collection->ns().isDropPendingNamespace()) {
+ auto viewNss = collection->ns().getTimeseriesViewNamespace();
+ auto view =
+ catalog->lookupViewWithoutValidatingDurable(opCtx, viewNss);
+ if (view && view->timeseries() &&
+ (!authorizedCollections ||
+ as->isAuthorizedForAnyActionOnResource(
+ ResourcePattern::forExactNamespace(viewNss)))) {
+ // The time-series view for this buckets namespace exists, so
+ // add it here while we have the collection options.
+ _addWorkingSetMember(opCtx,
+ buildTimeseriesBson(collection, nameOnly),
+ matcher.get(),
+ ws.get(),
+ root.get());
+ }
}
if (authorizedCollections &&