From c09e27d0ea8b535a3a766924c141116c801f641a Mon Sep 17 00:00:00 2001 From: Henrik Edin Date: Mon, 24 May 2021 11:28:20 -0400 Subject: SERVER-56883 Fix db.collection.stats() error on mongos when calling on timeseries collection --- src/mongo/s/commands/cluster_coll_stats_cmd.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/mongo/s/commands') diff --git a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp index 8dd6772c8d9..fe30992c35f 100644 --- a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp +++ b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp @@ -168,7 +168,10 @@ public: // We don't know the order that we will encounter the count and size, so we save them // until we've iterated through all the fields before updating unscaledCollSize - const auto shardObjCount = static_cast(res["count"].Number()); + // Timeseries bucket collection does not provide 'count' or 'avgObjSize'. + BSONElement countField = res.getField("count"); + const auto shardObjCount = + static_cast(!countField.eoo() ? countField.Number() : 0); for (const auto& e : res) { StringData fieldName = e.fieldNameStringData(); @@ -192,6 +195,7 @@ public: counts[e.fieldName()] += e.numberLong(); } else if (fieldName == "avgObjSize") { const auto shardAvgObjSize = e.numberLong(); + uassert(5688300, "'avgObjSize' provided but not 'count'", !countField.eoo()); unscaledCollSize += shardAvgObjSize * shardObjCount; } else if (fieldName == "maxSize") { const auto shardMaxSize = e.numberLong(); -- cgit v1.2.1