fix: filter out views in mongodb lookup (#11280)

This commit is contained in:
Joshua Powers 2022-06-21 11:16:12 -06:00 committed by GitHub
parent 748290d5d0
commit 42a167ffde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -3,13 +3,13 @@ package mongodb
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson/primitive"
"strconv"
"strings"
"time"
"github.com/influxdata/telegraf"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/bsonx"
@ -229,8 +229,11 @@ func (s *Server) gatherCollectionStats(colStatsDbs []string) (*ColStats, error)
results := &ColStats{}
for _, dbName := range names {
if stringInSlice(dbName, colStatsDbs) || len(colStatsDbs) == 0 {
// skip views as they fail on collStats below
filter := bson.M{"type": bson.M{"$in": bson.A{"collection", "timeseries"}}}
var colls []string
colls, err = s.client.Database(dbName).ListCollectionNames(context.Background(), bson.D{})
colls, err = s.client.Database(dbName).ListCollectionNames(context.Background(), filter)
if err != nil {
s.Log.Errorf("Error getting collection names: %s", err.Error())
continue