@@ -443,7 +443,10 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
443
443
let started = 0 ;
444
444
if ( this . monitorCommands ) {
445
445
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
+ ) ;
447
450
}
448
451
449
452
let document ;
@@ -469,7 +472,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
469
472
message ,
470
473
options . noResponse ? undefined : document ,
471
474
started ,
472
- this [ kDescription ] . serverConnectionId
475
+ this . description . serverConnectionId
473
476
)
474
477
) ;
475
478
}
@@ -479,21 +482,29 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
479
482
}
480
483
} catch ( error ) {
481
484
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
492
494
)
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
+ }
497
508
}
498
509
throw error ;
499
510
}
0 commit comments