diff --git a/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java b/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java index cd4d5436a85..4751f1c98ef 100644 --- a/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java +++ b/collector/src/main/java/org/dromara/hertzbeat/collector/collect/mongodb/MongodbSingleCollectImpl.java @@ -112,6 +112,9 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a document = (Document) document.get(metricsParts[i]); } } + if (document == null) { + throw new RuntimeException("the document get from command " + metrics.getMongodb().getCommand() + " is null."); + } fillBuilder(metrics, valueRowBuilder, document); builder.addValues(valueRowBuilder.build()); } catch (MongoServerUnavailableException | MongoTimeoutException unavailableException) { @@ -137,7 +140,7 @@ public String supportProtocol() { private void fillBuilder(Metrics metrics, CollectRep.ValueRow.Builder valueRowBuilder, Document document) { metrics.getAliasFields().forEach(it -> { if (document.containsKey(it)) { - Object fieldValue =document.get(it); + Object fieldValue = document.get(it); if (fieldValue == null) { valueRowBuilder.addColumns(CommonConstants.NULL_VALUE); } else {