File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { Document } from './bson';
22import { MongoRuntimeError , MongoTransactionError } from './error' ;
33import type { CommandOperationOptions } from './operations/command' ;
44import { ReadConcern , ReadConcernLike } from './read_concern' ;
5+ import type { ReadPreferenceLike } from './read_preference' ;
56import { ReadPreference } from './read_preference' ;
67import type { Server } from './sdam/server' ;
78import { WriteConcern } from './write_concern' ;
@@ -67,7 +68,7 @@ export interface TransactionOptions extends CommandOperationOptions {
6768 /** A default writeConcern for commands in this transaction */
6869 writeConcern ?: WriteConcern ;
6970 /** A default read preference for commands in this transaction */
70- readPreference ?: ReadPreference ;
71+ readPreference ?: ReadPreferenceLike ;
7172 /** Specifies the maximum amount of time to allow a commit action on a transaction to run in milliseconds */
7273 maxCommitTimeMS ?: number ;
7374}
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ async function runTransactionWithRetry(
4848
4949async function updateEmployeeInfo ( client : MongoClient , session : ClientSession ) {
5050 session . startTransaction ( {
51+ readPreference : 'primary' ,
5152 readConcern : new ReadConcern ( 'available' ) , // NODE-3297
5253 writeConcern : { w : 'majority' }
5354 } ) ;
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai' ;
2+
3+ import { ReadPreference } from '../../src' ;
4+ import { Transaction } from '../../src/transactions' ;
5+
6+ describe ( 'class Transaction' , ( ) => {
7+ describe ( 'constructor()' , ( ) => {
8+ it ( 'uses ReadPreference instance' , ( ) => {
9+ const transaction = new Transaction ( {
10+ readPreference : ReadPreference . nearest
11+ } ) ;
12+ expect ( transaction . options )
13+ . to . have . property ( 'readPreference' )
14+ . that . is . instanceOf ( ReadPreference )
15+ . that . has . property ( 'mode' , 'nearest' ) ;
16+ } ) ;
17+
18+ it ( 'transforms ReadPreferenceLike string' , ( ) => {
19+ const transaction = new Transaction ( {
20+ readPreference : 'nearest'
21+ } ) ;
22+ expect ( transaction . options )
23+ . to . have . property ( 'readPreference' )
24+ . that . is . instanceOf ( ReadPreference )
25+ . that . has . property ( 'mode' , 'nearest' ) ;
26+ } ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments