Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pool-monitor
poolMonitor := &event.PoolMonitor{
Event: func(e *event.PoolEvent) {
switch e.Type {
case event.PoolCreated:
// mongo-connection pool creation events.
connPoolCreated++
case event.GetSucceeded:
// succesful mongo connection established by the pool
connSuccess++
case event.ConnectionClosed:
// mongo-connection gets closed
connClosed++
case event.ConnectionReturned:
// connection instance returns to the pool after completing a mongo transaction.
connReturned++
case event.PoolCleared:
// PoolCleared event will remove all the connections from the pool
connPoolCleared++
}
},
}
client, err := mongo.NewClient(options.Client().
ApplyURI("mongodb://<username>:<password>@localhost:27017").SetPoolMonitor(poolMonitor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment