@@ -443,7 +443,10 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
443443 let started = 0 ;
444444 if ( this . monitorCommands ) {
445445 started = now ( ) ;
446- this . emit ( Connection . COMMAND_STARTED , new CommandStartedEvent ( this , message ) ) ;
446+ this . emit (
447+ Connection . COMMAND_STARTED ,
448+ new CommandStartedEvent ( this , message , this . description . serverConnectionId )
449+ ) ;
447450 }
448451
449452 let document ;
@@ -469,7 +472,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
469472 message ,
470473 options . noResponse ? undefined : document ,
471474 started ,
472- this [ kDescription ] . serverConnectionId
475+ this . description . serverConnectionId
473476 )
474477 ) ;
475478 }
@@ -479,21 +482,29 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
479482 }
480483 } catch ( error ) {
481484 if ( this . monitorCommands ) {
482- error . name === 'MongoWriteConcernError'
483- ? this . emit (
484- Connection . COMMAND_SUCCEEDED ,
485- new CommandSucceededEvent (
486- this ,
487- message ,
488- options . noResponse ? undefined : document ,
489- started ,
490- this [ kDescription ] . serverConnectionId
491- )
485+ if ( error . name === 'MongoWriteConcernError' ) {
486+ this . emit (
487+ Connection . COMMAND_SUCCEEDED ,
488+ new CommandSucceededEvent (
489+ this ,
490+ message ,
491+ options . noResponse ? undefined : document ,
492+ started ,
493+ this . description . serverConnectionId
492494 )
493- : this . emit (
494- Connection . COMMAND_FAILED ,
495- new CommandFailedEvent ( this , message , error , started )
496- ) ;
495+ ) ;
496+ } else {
497+ this . emit (
498+ Connection . COMMAND_FAILED ,
499+ new CommandFailedEvent (
500+ this ,
501+ message ,
502+ error ,
503+ started ,
504+ this . description . serverConnectionId
505+ )
506+ ) ;
507+ }
497508 }
498509 throw error ;
499510 }
0 commit comments