File tree 3 files changed +31
-1
lines changed
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';
2
2
import { MongoRuntimeError , MongoTransactionError } from './error' ;
3
3
import type { CommandOperationOptions } from './operations/command' ;
4
4
import { ReadConcern , ReadConcernLike } from './read_concern' ;
5
+ import type { ReadPreferenceLike } from './read_preference' ;
5
6
import { ReadPreference } from './read_preference' ;
6
7
import type { Server } from './sdam/server' ;
7
8
import { WriteConcern } from './write_concern' ;
@@ -67,7 +68,7 @@ export interface TransactionOptions extends CommandOperationOptions {
67
68
/** A default writeConcern for commands in this transaction */
68
69
writeConcern ?: WriteConcern ;
69
70
/** A default read preference for commands in this transaction */
70
- readPreference ?: ReadPreference ;
71
+ readPreference ?: ReadPreferenceLike ;
71
72
/** Specifies the maximum amount of time to allow a commit action on a transaction to run in milliseconds */
72
73
maxCommitTimeMS ?: number ;
73
74
}
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ async function runTransactionWithRetry(
48
48
49
49
async function updateEmployeeInfo ( client : MongoClient , session : ClientSession ) {
50
50
session . startTransaction ( {
51
+ readPreference : 'primary' ,
51
52
readConcern : new ReadConcern ( 'available' ) , // NODE-3297
52
53
writeConcern : { w : 'majority' }
53
54
} ) ;
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