@@ -511,10 +511,15 @@ function resolveReadPreference(options, sources) {
511
511
const db = sources . db ;
512
512
const coll = sources . collection ;
513
513
const defaultReadPreference = sources . default ;
514
+ const session = options . session ;
514
515
515
516
let readPreference ;
516
517
if ( options . readPreference ) {
517
518
readPreference = options . readPreference ;
519
+ } else if ( session && session . inTransaction ( ) && session . transaction . options . readPreference ) {
520
+ // From transactions spec: If the user supplies an explicit readConcern via a method
521
+ // option, however, drivers MUST apply the readConcern...
522
+ readPreference = session . transaction . options . readPreference ;
518
523
} else if ( coll && coll . s . readPreference ) {
519
524
readPreference = coll . s . readPreference ;
520
525
} else if ( db && db . s . readPreference ) {
@@ -583,20 +588,18 @@ function decorateWithCollation(command, target, options) {
583
588
}
584
589
}
585
590
586
- function decorateWithReadConcern ( command , coll , options ) {
591
+ /**
592
+ * Applies a read concern to a given command.
593
+ *
594
+ * @param {object } command the command on which to apply the read concern
595
+ * @param {Collection } [target] the parent collection of the operation calling this method
596
+ */
597
+ function decorateWithReadConcern ( command , coll ) {
587
598
let readConcern = Object . assign ( { } , command . readConcern || { } ) ;
588
599
if ( coll . s . readConcern ) {
589
600
Object . assign ( readConcern , coll . s . readConcern ) ;
590
601
}
591
602
592
- if (
593
- options . session &&
594
- options . session . supports . causalConsistency &&
595
- options . session . operationTime
596
- ) {
597
- Object . assign ( readConcern , { afterClusterTime : options . session . operationTime } ) ;
598
- }
599
-
600
603
if ( Object . keys ( readConcern ) . length > 0 ) {
601
604
Object . assign ( command , { readConcern : readConcern } ) ;
602
605
}
0 commit comments