Skip to content

Commit

Permalink
fix: filter out views in mongodb lookup (#11280)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Jun 21, 2022
1 parent 748290d commit 42a167f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plugins/inputs/mongodb/mongodb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 42a167f

Please sign in to comment.