summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_coll_stats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_coll_stats.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_coll_stats.cpp61
1 files changed, 26 insertions, 35 deletions
diff --git a/src/mongo/db/pipeline/document_source_coll_stats.cpp b/src/mongo/db/pipeline/document_source_coll_stats.cpp
index a947f1589e6..c00f5fcd44d 100644
--- a/src/mongo/db/pipeline/document_source_coll_stats.cpp
+++ b/src/mongo/db/pipeline/document_source_coll_stats.cpp
@@ -71,15 +71,18 @@ intrusive_ptr<DocumentSource> DocumentSourceCollStats::createFromBson(
return make_intrusive<DocumentSourceCollStats>(pExpCtx, std::move(spec));
}
-BSONObj DocumentSourceCollStats::makeStatsForNs(
- const boost::intrusive_ptr<ExpressionContext>& expCtx,
- const NamespaceString& nss,
- const DocumentSourceCollStatsSpec& spec) {
+DocumentSource::GetNextResult DocumentSourceCollStats::doGetNext() {
+ if (_finished) {
+ return GetNextResult::makeEOF();
+ }
+
+ _finished = true;
+
BSONObjBuilder builder;
- builder.append("ns", nss.ns());
+ builder.append("ns", pExpCtx->ns.ns());
- auto shardName = expCtx->mongoProcessInterface->getShardName(expCtx->opCtx);
+ auto shardName = pExpCtx->mongoProcessInterface->getShardName(pExpCtx->opCtx);
if (!shardName.empty()) {
builder.append("shard", shardName);
@@ -88,49 +91,37 @@ BSONObj DocumentSourceCollStats::makeStatsForNs(
builder.append("host", getHostNameCachedAndPort());
builder.appendDate("localTime", jsTime());
- if (auto latencyStatsSpec = spec.getLatencyStats()) {
- // getRequestOnTimeseriesView is set to true if collstats is called on the view.
- auto resolvedNss =
- spec.getRequestOnTimeseriesView() ? nss.getTimeseriesViewNamespace() : nss;
- expCtx->mongoProcessInterface->appendLatencyStats(
- expCtx->opCtx, resolvedNss, latencyStatsSpec->getHistograms(), &builder);
+ if (auto latencyStatsSpec = _collStatsSpec.getLatencyStats()) {
+ pExpCtx->mongoProcessInterface->appendLatencyStats(
+ pExpCtx->opCtx, pExpCtx->ns, latencyStatsSpec->getHistograms(), &builder);
}
- if (auto storageStats = spec.getStorageStats()) {
+ if (auto storageStats = _collStatsSpec.getStorageStats()) {
// If the storageStats field exists, it must have been validated as an object when parsing.
BSONObjBuilder storageBuilder(builder.subobjStart("storageStats"));
- uassertStatusOKWithContext(expCtx->mongoProcessInterface->appendStorageStats(
- expCtx->opCtx, nss, *storageStats, &storageBuilder),
+ uassertStatusOKWithContext(pExpCtx->mongoProcessInterface->appendStorageStats(
+ pExpCtx->opCtx, pExpCtx->ns, *storageStats, &storageBuilder),
"Unable to retrieve storageStats in $collStats stage");
storageBuilder.doneFast();
}
- if (spec.getCount()) {
- uassertStatusOKWithContext(
- expCtx->mongoProcessInterface->appendRecordCount(expCtx->opCtx, nss, &builder),
- "Unable to retrieve count in $collStats stage");
+ if (_collStatsSpec.getCount()) {
+ uassertStatusOKWithContext(pExpCtx->mongoProcessInterface->appendRecordCount(
+ pExpCtx->opCtx, pExpCtx->ns, &builder),
+ "Unable to retrieve count in $collStats stage");
}
- if (spec.getQueryExecStats()) {
- uassertStatusOKWithContext(
- expCtx->mongoProcessInterface->appendQueryExecStats(expCtx->opCtx, nss, &builder),
- "Unable to retrieve queryExecStats in $collStats stage");
+ if (_collStatsSpec.getQueryExecStats()) {
+ uassertStatusOKWithContext(pExpCtx->mongoProcessInterface->appendQueryExecStats(
+ pExpCtx->opCtx, pExpCtx->ns, &builder),
+ "Unable to retrieve queryExecStats in $collStats stage");
}
- return builder.obj();
-}
-
-DocumentSource::GetNextResult DocumentSourceCollStats::doGetNext() {
- if (_finished) {
- return GetNextResult::makeEOF();
- }
-
- _finished = true;
- return {Document(makeStatsForNs(pExpCtx, pExpCtx->ns, _collStatsSpec))};
+ return {Document(builder.obj())};
}
-Value DocumentSourceCollStats::serialize(const SerializationOptions& opts) const {
- return Value(Document{{getSourceName(), _collStatsSpec.toBSON(opts)}});
+Value DocumentSourceCollStats::serialize(boost::optional<ExplainOptions::Verbosity> explain) const {
+ return Value(Document{{getSourceName(), _collStatsSpec.toBSON()}});
}
} // namespace mongo