Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/mongoproxy/plugins/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/insort"
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/limits"
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/mongo"
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/nohint"
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/opentracing"
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/schema"
_ "github.com/wish/mongoproxy/pkg/mongoproxy/plugins/slowlog"
Expand Down
3 changes: 3 additions & 0 deletions pkg/mongoproxy/plugins/nohint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# nohint

This plugin simply removes all hints from incoming queries
59 changes: 59 additions & 0 deletions pkg/mongoproxy/plugins/nohint/nohint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package nohint

import (
"context"

"go.mongodb.org/mongo-driver/bson"

"github.com/wish/mongoproxy/pkg/command"
"github.com/wish/mongoproxy/pkg/mongoproxy/plugins"
)

const (
Name = "nohint"
)

func init() {
plugins.Register(func() plugins.Plugin {
return &NohintPlugin{}
})
}

// This is a plugin that simply strips hints out
type NohintPlugin struct {
}

func (p *NohintPlugin) Name() string { return Name }

// Configure configures this plugin with the given configuration object. Returns
// an error if the configuration is invalid for the plugin.
func (p *NohintPlugin) Configure(d bson.D) error {
return nil
}

// Process is the function executed when a message is called in the pipeline.
func (p *NohintPlugin) Process(ctx context.Context, r *plugins.Request, next plugins.PipelineFunc) (bson.D, error) {
switch cmd := r.Command.(type) {

case *command.Aggregate:
cmd.Hint = nil

case *command.Count:
cmd.Hint = nil

case *command.Delete:
cmd.Hint = nil

case *command.Find:
cmd.Hint = nil

case *command.Update:
for i, u := range cmd.Updates {
if u.Hint != nil {
u.Hint = nil
cmd.Updates[i] = u
}
}
}
return next(ctx, r)
}