1
- from pymongo import MongoClient
1
+ from pymongo import MongoClient , AsyncMongoClient
2
2
from pymongo .monitoring import CommandListener , CommandSucceededEvent , ServerListener , \
3
3
ConnectionPoolListener , ServerHeartbeatStartedEvent , \
4
4
ConnectionCreatedEvent
5
5
6
- # start-monitoring
6
+ # start-monitoring-listeners
7
7
class MyCommandListener (CommandListener ):
8
8
def succeeded (self , event : CommandSucceededEvent ):
9
9
print (f"Command { event .command_name } succeeded" )
@@ -21,7 +21,14 @@ def connection_created(self, event: ConnectionCreatedEvent):
21
21
print (f"Connection { event .connection_id } created" )
22
22
23
23
# Include other event method implementations here
24
+ # end-monitoring-listeners
24
25
26
+ # start-monitoring-client
25
27
listeners = [MyCommandListener (), MyServerListener (), MyPoolListener ()]
26
28
client = MongoClient ("<connection URI>" , event_listeners = listeners )
27
- # end-monitoring
29
+ # end-monitoring-client
30
+
31
+ # start-monitoring-client-async
32
+ listeners = [MyCommandListener (), MyServerListener (), MyPoolListener ()]
33
+ client = AsyncMongoClient ("<connection URI>" , event_listeners = listeners )
34
+ # end-monitoring-client-async
0 commit comments