@@ -484,22 +484,23 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
484
484
485
485
command (
486
486
ns : MongoDBNamespace ,
487
- cmd : Document ,
487
+ command : Document ,
488
488
options : CommandOptions | undefined ,
489
489
callback : Callback
490
490
) : void {
491
- const readPreference = getReadPreference ( cmd , options ) ;
491
+ let cmd = { ...command } ;
492
+
493
+ const readPreference = getReadPreference ( options ) ;
492
494
const shouldUseOpMsg = supportsOpMsg ( this ) ;
493
495
const session = options ?. session ;
494
496
495
497
let clusterTime = this . clusterTime ;
496
- let finalCmd = Object . assign ( { } , cmd ) ;
497
498
498
499
if ( this . serverApi ) {
499
500
const { version, strict, deprecationErrors } = this . serverApi ;
500
- finalCmd . apiVersion = version ;
501
- if ( strict != null ) finalCmd . apiStrict = strict ;
502
- if ( deprecationErrors != null ) finalCmd . apiDeprecationErrors = deprecationErrors ;
501
+ cmd . apiVersion = version ;
502
+ if ( strict != null ) cmd . apiStrict = strict ;
503
+ if ( deprecationErrors != null ) cmd . apiDeprecationErrors = deprecationErrors ;
503
504
}
504
505
505
506
if ( hasSessionSupport ( this ) && session ) {
@@ -511,7 +512,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
511
512
clusterTime = session . clusterTime ;
512
513
}
513
514
514
- const err = applySession ( session , finalCmd , options ) ;
515
+ const err = applySession ( session , cmd , options ) ;
515
516
if ( err ) {
516
517
return callback ( err ) ;
517
518
}
@@ -521,12 +522,12 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
521
522
522
523
// if we have a known cluster time, gossip it
523
524
if ( clusterTime ) {
524
- finalCmd . $clusterTime = clusterTime ;
525
+ cmd . $clusterTime = clusterTime ;
525
526
}
526
527
527
528
if ( isSharded ( this ) && ! shouldUseOpMsg && readPreference && readPreference . mode !== 'primary' ) {
528
- finalCmd = {
529
- $query : finalCmd ,
529
+ cmd = {
530
+ $query : cmd ,
530
531
$readPreference : readPreference . toJSON ( )
531
532
} ;
532
533
}
@@ -544,8 +545,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
544
545
545
546
const cmdNs = `${ ns . db } .$cmd` ;
546
547
const message = shouldUseOpMsg
547
- ? new Msg ( cmdNs , finalCmd , commandOptions )
548
- : new Query ( cmdNs , finalCmd , commandOptions ) ;
548
+ ? new Msg ( cmdNs , cmd , commandOptions )
549
+ : new Query ( cmdNs , cmd , commandOptions ) ;
549
550
550
551
try {
551
552
write ( this , message , commandOptions , callback ) ;
0 commit comments