Created
August 24, 2021 11:51
-
-
Save Deeptiman/96320d9dae0d8a46a77f34e0f817b656 to your computer and use it in GitHub Desktop.
command-monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmdMonitor := &event.CommandMonitor{ | |
Started: func(_ context.Context, evt *event.CommandStartedEvent) { | |
// Command Started event triggered when a mongo query transaction prepares the command lifecycle for | |
// certain DatabaseName | |
CommandStartedEvent { | |
Command bson.Raw // base64 hash value of the mongo query transaction raw | |
DatabaseName string // mongodb database name | |
CommandName string // mongodb query name [ping,insert,update,find] | |
RequestID int64 // mongo query command unique ID | |
ConnectionID string // connection string for mongo instance | |
} | |
}, | |
Succeeded: func(_ context.Context, evt *event.CommandSucceededEvent) { | |
// Command Succeeded event triggered when a mongo query transaction gets successful | |
CommandSucceededEvent { | |
CommandFinishedEvent // CommandFinishedEvent will contain the basic cmd event details | |
Reply bson.Raw // response base64 hash for a successfully executed cmd | |
} | |
}, | |
Failed: func(_ context.Context, evt *event.CommandFailedEvent) { | |
// Command Failed event triggered when a mongo query transaction failed | |
CommandFailedEvent { | |
CommandFinishedEvent // CommandFinishedEvent will contain the basic cmd event details | |
Failure string // failure error message for the mongo-query | |
} | |
}, | |
} | |
client, err := mongo.NewClient(options.Client(). | |
ApplyURI("mongodb://<username>:<password>@localhost:27017").SetMonitor(cmdMonitor)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment