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-04 19:03:03 +0000
commitf438adfc83076f28919bc9b9b55477b4994e9e71 (patch)
tree804ee2e64700c1d30c68d7317ca8874aef498d28
parenta4d4fa6104bf04ae38b5e63334c77392799a9d13 (diff)
downloadmongo-f438adfc83076f28919bc9b9b55477b4994e9e71.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 f78cfda6308..39bb826fd79 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -167,9 +167,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;
@@ -377,8 +375,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
@@ -397,21 +394,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 &&