diff --git a/plugins/inputs/mongodb/mongodb_data_test.go b/plugins/inputs/mongodb/mongodb_data_test.go
index 9a5793f7194c0cfd44a6b72b8748f2e3b4581785..21541dd957c7104201b69459ca5c3a2299e30c0f 100644
--- a/plugins/inputs/mongodb/mongodb_data_test.go
+++ b/plugins/inputs/mongodb/mongodb_data_test.go
@@ -1,6 +1,7 @@
 package mongodb
 
 import (
+	"sort"
 	"testing"
 	"time"
 
@@ -152,7 +153,8 @@ func TestAddShardHostStats(t *testing.T) {
 		assert.True(t, acc.HasTag("mongodb_shard_stats", "hostname"))
 		hostsFound = append(hostsFound, host)
 	}
-
+	sort.Strings(hostsFound)
+	sort.Strings(expectedHosts)
 	assert.Equal(t, hostsFound, expectedHosts)
 }