summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPol Pinol Castuera <pol.pinol@mongodb.com>2022-11-24 07:37:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-24 08:20:16 +0000
commit1557a827b0ea179cf64b3e4139169033e2181a59 (patch)
tree4b10be27f61f1584d3e69b02dbf9806580200429
parent637fb52801843d2dc1b9dd212116d0ec2973e8d5 (diff)
downloadmongo-1557a827b0ea179cf64b3e4139169033e2181a59.tar.gz
SERVER-71477 Check '_internalAllCollectionStatsSpec.getStats()' exists before calling 'makeStatsForNs'
-rw-r--r--etc/backports_required_for_multiversion_tests.yml4
-rw-r--r--jstests/sharding/all_collection_stats.js4
-rw-r--r--src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp14
-rw-r--r--src/mongo/db/pipeline/document_source_internal_all_collection_stats.h2
4 files changed, 17 insertions, 7 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index b91f68ce1b5..b87e30395c0 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -226,6 +226,8 @@ last-continuous:
ticket: SERVER-70436
- test_file: jstests/sharding/prepare_transaction_then_migrate.js
ticket: SERVER-68361
+ - test_file: jstests/sharding/all_collection_stats.js
+ ticket: SERVER-71477
suites: null
last-lts:
all:
@@ -529,4 +531,6 @@ last-lts:
ticket: SERVER-70436
- test_file: jstests/sharding/prepare_transaction_then_migrate.js
ticket: SERVER-68361
+ - test_file: jstests/sharding/all_collection_stats.js
+ ticket: SERVER-71477
suites: null
diff --git a/jstests/sharding/all_collection_stats.js b/jstests/sharding/all_collection_stats.js
index 5ef72a2dee8..2fd89236e70 100644
--- a/jstests/sharding/all_collection_stats.js
+++ b/jstests/sharding/all_collection_stats.js
@@ -67,6 +67,10 @@ for (let i = 0; i < 20; i++) {
assert(exists);
}
+// Test valid query with empty specification
+assert.commandWorked(
+ adminDb.runCommand({aggregate: 1, pipeline: [{$_internalAllCollectionStats: {}}], cursor: {}}));
+
// Test invalid queries/values.
assert.commandFailedWithCode(
adminDb.runCommand({aggregate: 1, pipeline: [{$_internalAllCollectionStats: 3}], cursor: {}}),
diff --git a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp
index ec7350bc63e..6c9693e0443 100644
--- a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp
+++ b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp
@@ -61,12 +61,14 @@ DocumentSource::GetNextResult DocumentSourceInternalAllCollectionStats::doGetNex
continue;
}
- try {
- return {Document{DocumentSourceCollStats::makeStatsForNs(
- pExpCtx, nss, _internalAllCollectionStatsSpec.getStats().get())}};
- } catch (const ExceptionFor<ErrorCodes::CommandNotSupportedOnView>&) {
- // We don't want to retrieve data for views, only for collections.
- continue;
+ if (const auto& stats = _internalAllCollectionStatsSpec.getStats()) {
+ try {
+ return {
+ Document{DocumentSourceCollStats::makeStatsForNs(pExpCtx, nss, stats.get())}};
+ } catch (const ExceptionFor<ErrorCodes::CommandNotSupportedOnView>&) {
+ // We don't want to retrieve data for views, only for collections.
+ continue;
+ }
}
}
diff --git a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h
index 92b57d55e55..38324fb51ad 100644
--- a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h
+++ b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h
@@ -117,7 +117,7 @@ private:
// The specification object given to $_internalAllCollectionStats containing user specified
// options.
- DocumentSourceInternalAllCollectionStatsSpec _internalAllCollectionStatsSpec;
+ const DocumentSourceInternalAllCollectionStatsSpec _internalAllCollectionStatsSpec;
boost::optional<std::deque<BSONObj>> _catalogDocs;
// A $match stage can be absorbed in order to avoid unnecessarily computing the stats for