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.
-
2This is called command monitoring, see e.g. docs.mongodb.com/ruby-driver/master/tutorials/….D. SM– D. SM2021-04-03 20:52:20 +00:00Commented Apr 3, 2021 at 20:52
-
1Thank you, you were right. Unfortunately go mongodb package has the worst documentation ever created :/nexequ– nexequ2021-04-03 21:18:44 +00:00Commented Apr 3, 2021 at 21:18
Add a comment
|
1 Answer
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)
1 Comment
Jakobii