3

I'm trying to print mongodb query created with "go.mongodb.org/mongo-driver/mongo" package. Is there any option to take a look at the query produced by this package or dump it in any way? I can go inside mongod instance and modify profiling level and see the queries from mongod, but it's not the right way.

2
  • 2
    This is called command monitoring, see e.g. docs.mongodb.com/ruby-driver/master/tutorials/…. Commented Apr 3, 2021 at 20:52
  • 1
    Thank you, you were right. Unfortunately go mongodb package has the worst documentation ever created :/ Commented Apr 3, 2021 at 21:18

1 Answer 1

13

Thanks to user D. SM I've got a code sample to achieve monitoring of all logs.

cmdMonitor := &event.CommandMonitor{
    Started: func(_ context.Context, evt *event.CommandStartedEvent) {
        log.Print(evt.Command)
    },
}
ctx := context.Background()
clientOpts := options.Client().ApplyURI(connectionString).SetMonitor(cmdMonitor)
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.