summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Brock <tyler.brock@gmail.com>2023-01-30 16:10:03 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-30 17:21:36 +0000
commit942e2e9541f97448538e603c0fb14967d577e633 (patch)
treefa2b7a10995bfe01638d8b287a026ecee2a9c434
parent5645c1e6e98edf640ae295e29eff20872c2700fb (diff)
downloadmongo-942e2e9541f97448538e603c0fb14967d577e633.tar.gz
SERVER-72620 ensure shard added to $indexStats for unsharded collections
-rw-r--r--jstests/aggregation/sources/indexStats/verify_index_stats_output.js3
-rw-r--r--src/mongo/db/pipeline/document_source_index_stats.cpp5
2 files changed, 7 insertions, 1 deletions
diff --git a/jstests/aggregation/sources/indexStats/verify_index_stats_output.js b/jstests/aggregation/sources/indexStats/verify_index_stats_output.js
index bb86ee184c5..f82b52b0b18 100644
--- a/jstests/aggregation/sources/indexStats/verify_index_stats_output.js
+++ b/jstests/aggregation/sources/indexStats/verify_index_stats_output.js
@@ -47,6 +47,7 @@ let shardsFound = [];
db.getSiblingDB("config").shards.find().forEach(function(shard) {
allShards.push(shard._id);
});
+const isShardedCluster = !!allShards.length;
for (const indexStats of pausedOutput) {
assert.hasFields(indexStats, ["building", "spec"]);
@@ -62,6 +63,8 @@ for (const indexStats of pausedOutput) {
// names of known shards.
if (indexStats.hasOwnProperty("shard")) {
shardsFound.push(indexStats["shard"]);
+ } else {
+ assert(!isShardedCluster);
}
}
diff --git a/src/mongo/db/pipeline/document_source_index_stats.cpp b/src/mongo/db/pipeline/document_source_index_stats.cpp
index 5612135cd78..dc59d29d454 100644
--- a/src/mongo/db/pipeline/document_source_index_stats.cpp
+++ b/src/mongo/db/pipeline/document_source_index_stats.cpp
@@ -50,7 +50,10 @@ const char* DocumentSourceIndexStats::getSourceName() const {
DocumentSource::GetNextResult DocumentSourceIndexStats::doGetNext() {
if (_indexStats.empty()) {
_indexStats = pExpCtx->mongoProcessInterface->getIndexStats(
- pExpCtx->opCtx, pExpCtx->ns, _processName, pExpCtx->fromMongos);
+ pExpCtx->opCtx,
+ pExpCtx->ns,
+ _processName,
+ serverGlobalParams.clusterRole != ClusterRole::None);
_indexStatsIter = _indexStats.cbegin();
}