Debug query with offical mongodb golang package (command monitoring)

Viewed 1631

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.

1 Answers

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)
Related