Hi @TopherGopher,
The easiest way to do this would be via our Command Monitoring API. If you’re just looking to log commands and server responses, you could do something like this:
monitor := &event.CommandMonitor {
Started: func(_ context.Context, e *event.CommandStartedEvent) {
fmt.Println(e.Command)
},
Succeeded: func(_ context.Context, e *event.CommandSucceededEvent) {
fmt.Println(e.Reply)
},
Failure: func(_ context.Context, e *event.CommandFailedEvent) {
fmt.Println(e.Failure)
},
}
opts := options.Client().SetMonitor(monitor)
client, err := mongo.Connect(ctx, opts)
This will log all of the commands sent to the server as well as the server’s response or an error that occurred. If you have an application that does multiple concurrent operations, the logs may have started/succeed/failed events for different operations interleaved with each other. If you want to log the CommandStartedEvent for an operation along with it’s CommandSucceededEvent/CommandFailedEvent, you can use the RequestID field in the events to correlate them (perhaps using something like Go’s sync.Map type).
– Divjot