@@ -511,10 +511,15 @@ function resolveReadPreference(options, sources) {
511511 const db = sources . db ;
512512 const coll = sources . collection ;
513513 const defaultReadPreference = sources . default ;
514+ const session = options . session ;
514515
515516 let readPreference ;
516517 if ( options . readPreference ) {
517518 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 ;
518523 } else if ( coll && coll . s . readPreference ) {
519524 readPreference = coll . s . readPreference ;
520525 } else if ( db && db . s . readPreference ) {
@@ -583,20 +588,18 @@ function decorateWithCollation(command, target, options) {
583588 }
584589}
585590
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 ) {
587598 let readConcern = Object . assign ( { } , command . readConcern || { } ) ;
588599 if ( coll . s . readConcern ) {
589600 Object . assign ( readConcern , coll . s . readConcern ) ;
590601 }
591602
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-
600603 if ( Object . keys ( readConcern ) . length > 0 ) {
601604 Object . assign ( command , { readConcern : readConcern } ) ;
602605 }
0 commit comments